Re: De-allocating memory - time issue
- Posted by Robert Craig <rds at RapidEuphoria.com> Sep 21, 2002
- 819 views
rforno writes: > t = repeat(repeat(repeat(1.13218966051, 3000), 100), 50) After executing this (type of) statement, in almost any language but Euphoria, you would have 3000x100x50 = 15 million (8-byte or more) copies of 1.13218966051 stored in memory. In Euphoria, you will have 3000 4-byte pointers to a *single* copy of 1.13218966051. You will also have 100 4-byte pointers to a *single* copy of the 3000-element sequence. You will also have 50 4-byte pointers to a *single* copy of the 100-element sequence. Instead of using 15 million x 8 bytes = 120,000,000 bytes of storage, Euphoria will use only 3000x4+100x4+50x4 = 12,600 bytes plus the storage for *one* copy of 1.13218966051. > for i = 1 to 50 do > for j = 1 to 100 do > for k = 1 to 3000 do > t[i][j][k] = 1.31764903217 > end for > end for > end for During execution of the above nested loops, copies will be made of all the sequences at each level. There will now be 15 million 4-byte pointers to a *single* copy of 1.31764903217. So you are still using much less memory than other languages. > But if I perform a floating point calculation like: > t[i][j][k] = (i * j * k) * 1.31764903217 > it lasts a long while Now it's no longer possible to have lots of pointers to a single floating-point value. You are creating a different f.p. value to store in each element. So you have created 15 million new floating-point values. Each floating-point value needs 8 bytes plus 4 bytes for a reference count, plus 4 bytes for malloc overhead. So you suddenly need 15 million x 16 = 240,000,000 bytes of *extra* storage in this case. Unless you have a lot of RAM on your machine, you will be faced with some very serious paging activity that will destroy your performance. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com