Al Bravo
Retired
Join date: 29 Jun 2004
Posts: 373
|
11-12-2004 13:16
When you declare a list does it preallocate all the memory it will use? I declare blank lists and dynamically add entries. Monitoring the free memory during these adds shows a constant figure. Can someone clarify?
|
Water Rogers
Registered User
Join date: 1 May 2003
Posts: 286
|
11-12-2004 13:55
preallocating would be something like list stuff = ["stuff 1", "stuff 2", "stuff 3"];
Declaring a blank list would only preallocate the memory needed to declare. Let's say you declare a blank list globaly, and then add 100 entries to it later - it's definately going to grow in memory.
A true way to preallocate a list knowing how many entries it will occupy max would be nice... like: MyList(5); a sort of array-ish way of declaring space needed to occupy that list with 5 entries allowed. That way, it would preallocate the neccessary memory needed for 5 entries in the list, even if it's blank.
--Water
_____________________
From: Philip Linden For the more technically minded - the problem is actually NOT the asset server (or 'asshat' as you prefer to affectionately call it herein).
|
Francis Chung
This sentence no verb.
Join date: 22 Sep 2003
Posts: 918
|
11-12-2004 16:32
I suspect the way that lists are implemented in LSL is with a linked list of arrays. (This is how java does it under the covers)
So, it will allocate memory for a list of, say, 10 items. If you use more than 10 items, it will allocate memory for another 10 items. It's a compromise between the speed & simplicity of arrays and the flexibility of linked lists.
_____________________
-- ~If you lived here, you would be home by now~
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
11-14-2004 18:08
LSL uses a 4 byte header for each entry in a list. And LSL uses pass-by-value for *everything*, including lists. I'm pretty sure it doesn't do any pre-allocation. It wouldn't suprise me at all if LSL didn't actualy declare variables until they were first used.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
Adam Zaius
Deus
Join date: 9 Jan 2004
Posts: 1,483
|
11-14-2004 18:52
From: Francis Chung I suspect the way that lists are implemented in LSL is with a linked list of arrays. (This is how java does it under the covers)
So, it will allocate memory for a list of, say, 10 items. If you use more than 10 items, it will allocate memory for another 10 items. It's a compromise between the speed & simplicity of arrays and the flexibility of linked lists. I think someone proved that it did this in batches of 3 array elements. -Adam
|