Results 1 to 10 of 38

Thread: PGD - Some thoughts about the future

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #19
    Quote Originally Posted by SilverWarior View Post
    @Andru
    I totally agree with you about dynamic arrays. I mean which idiot though about idea that best solution to increase the size of dynamic array is to double it's size?
    Imagine this: You have a byte array with 1024 items in it (using 1 KB of memory) and then you add just one item to it and it's size is doubled. Imagine that you have 1GB sized array and you add one new item. Utter stupidity..
    Idiot you say... Now, i don't know how the arrays actually work, but lets assume like you say that dynamic array doubles it on power of 2 margins.

    Imagine that you have [0..0] pointer array of size 1024 and you increase the size by 1 for 10 times in a row. Dynamic array makes only 1 memory allocation of 2kb, but pointer array makes reservation total over 10kb (1025, 1026...1034)! In addition to that, it's like a puzzle game in the memory - having odd sized memory blocks of random 1023, 1050 etc are harder to organize than if the blocks are evenly sized.
    (Oh, what also happens on array resizing, is existing memory copied to new array. Again Setlength() would win by big margin.)

    I haven't noticed much of a performance difference at all if you use dynamic arrays vs pointer arrays for texture memory. For most arrays you don't ever need to resize it, and when you do, dynamic arrays might win in performance. Previously i have known that TList follows the memory doubling method, but i am not sure about setlength(). And there are likely some limitations in higher amounts of memory, smaller reservations.
    Last edited by User137; 25-04-2014 at 06:50 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •