Page 4 of 4 FirstFirst ... 234
Results 31 to 38 of 38

Thread: PGD - Some thoughts about the future

  1. #31
    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.

  2. #32
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    Quote Originally Posted by User137 View Post
    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.)
    As an aside on this note, I'd be very interested in any tests/information anyone has on this. I use a lot of dynamic arrays that seem to behave themselves. My assumption is that its written that way to avoid causing memory fragmentation for memory sizes that scale linearly across all orders of magnitude (ie. there are x allocations done to get from 1KiB to 1MiB and another x allocations to get from 1MiB to 1GiB). I agree it could be better done. The question is what does it understand by 'allocate'? Is it allocating virtual, private or some other 'kind' of memory so that it has the memory needed/mapped/allocated but the OS can use it for other things until the array grows to that size?
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  3. #33
    Ups. I must admit that I have mixed arrays with Lists

  4. #34
    Quote Originally Posted by code_glitch View Post
    As an aside on this note, I'd be very interested in any tests/information anyone has on this.
    Iztok Kacin is trying to create better dynamical array by slicing it into smaller pieces. You can read some info on this on his blog here: http://www.cromis.net/blog/2013/03/i...-sliced-array/
    He also offers several comparion tests between his and regular dynamic arrays.

  5. #35
    PGDCE Developer de_jean_7777's Avatar
    Join Date
    Nov 2006
    Location
    Bosnia and Herzegovina (Herzegovina)
    Posts
    287
    Afaik dynamic arrays will only double in size only if you try to resize them. And it's existing size + new size. Resize will allocate new memory, copy over data and free the previous memory. In case the new size is smaller it is possible no reallocation will occur. Does not take up double memory, just the difference between new and old size, with a temporary need for additional memory while the array is reallocated. It does lead to memory fragmentation more easily. Also, the same will happen if you use a pointer to an array, and re-allocate the memory yourself. The same process happens, and dynamic arrays should not be that much slower than manual memory management. With dynamic arrays the compiler manages the memory and there is a small overhead (reference counting and what not). In any case, best to do as little resizing as possible. An idea for a benchmark.
    Existence is pain

  6. #36
    Memory management is not a problem. There was something else... but now I can see only speed down when Range Check error is enabled(and this is normal). So, there is one more reason to update my engine ) And I changed my mind a bit about Pascal compilers But I didn't test 64-bit version yet, e.g. FPC generates more instructions when there is a code using dynamic arrays, maybe there was something not optimal for 64-bit.

    update: Oh, now I remember, there were problems with throwing data via arrays between dll and application, and supporting C/C++. With time everything can be forgotten
    Last edited by Andru; 26-04-2014 at 10:54 AM.

  7. #37
    Speaking of contests;

    I now suddenly remember why I don't like contests. Because I participated in a contest once and I got disqualified because I broke the rules. Sort of. I don't think that I should describe in detail what exactly happened; the point is:
    If one wants to find a reason to disqualify other person, he|she will undoubtedly find one.

    On the other hand, for me following rules always seems unbelievably hard. It is difficult to pay attention to all those rules. Especially when there are two sets of rules: some general rules and rules specific to the ongoing contest. I always miss some points. And when I try to follow contest rules I just can't help but think "hey, I don't even get paid for this".

    And one more thing: I believe most contest organizers allow participants to use so called game creators. But I'm a programmer, I can't draw art for gaems, I can't write music; I am only good at writing code. So I really feel like I can't compete with ppl using game creator software who's also good at drawing and such; it just seems so pointless

  8. #38
    Quote Originally Posted by dj_sharp View Post
    And one more thing: I believe most contest organizers allow participants to use so called game creators.
    Those programs are usually refered as Game Worskhops.

    Quote Originally Posted by dj_sharp View Post
    But I'm a programmer, I can't draw art for gaems, I can't write music; I am only good at writing code. So I really feel like I can't compete with ppl using game creator software who's also good at drawing and such; it just seems so pointless
    Well I'm much like you more or less a programmer (average one).
    I'm not good at grawing hraphics,
    I haven't even tried composing music. Well did once and couldn't do it. End result was complete crap.
    But none of the above discouraged me in participating or trying to participate. So far I trieed twice but both time ended up with nothing to show as all I managed to did is some code without any GUI. So I never submited my entries.
    Infact failing to finish any of my entries actually gave me motivation to go and start making myself tools which might help me in the future:
    - texturing program where I could create ingame graphics in a way that I think would suite me
    - I developed an idea for a GUI library which should make GUI development much easier. Goal is to make library work with basically any graphical engine provided that you make suitable eader interface between my library and graphical engine.

    On the other note PGD competitions doesn't alow the use of readily made Game Workshops. You can use existing game engine provided that it is written in Objective Pascal. And that is the main reasony why I hapily try participating in them as I know that I athleast have some chance in being good.
    I suggest you check the previous competitions and their rules to get better idea on them.

Page 4 of 4 FirstFirst ... 234

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
  •