Skip to main content
gamedev.net
🔒 Locked

memory allocation

Started by manuQuetelard 8 replies 350+ views
Original Post
manuQuetelard
manuQuetelard
Hello, Since long time ago, I heard everywhere that memory allocation is very slow. how much slow really it is ?(more than a division? sqrt?). Thanks
manu
sphinx23
sphinx23
allocation must be slower than a division since division is implemented in hardware and memory allocation not.
however, it is not THAT slow, but you should avoid using it extensivly in the main game loop.
SwSh
SwSh
I''ve written a small test app to check how slow (or fast) mem allocation is. It allocates 10MB of memory and frees it again. Doing this in a 1000-times-loop takes about 1790 miliseconds on my K6-iii@450 with 192ram.
I think memory allocation is not so time consuming, as long as it doesn''t have to use virtual memory.
(I''ve also noticed that there is a _huge_ difference in speed between the ''release'' and ''debug'' build. But actually I was too impatient to wait for the debug version to success )


===========================
UNKNOWN caused an invalid page fault in module unknown at 0000:bff80eb6
: win98 with multiple sclerose
SwSh
SwSh
quote:
Original post by siaspete
In debug mode, the processor is spending much of the time filling that 10mb block with 0xCDCDCDCD ;-)



:D, or even 0x42696C6C, lol

===========================
UNKNOWN caused an invalid page fault in module unknown at 0000:bff80eb6
: win98 with multiple sclerose
smart_idiot
smart_idiot
What about 0xdeadbeef?
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other
SabreMan
SabreMan
quote:
Original post by SwSh
I''ve written a small test app to check how slow (or fast) mem allocation is. It allocates 10MB of memory and frees it again. Doing this in a 1000-times-loop takes about 1790 miliseconds on my K6-iii@450 with 192ram.

This doesn''t sound like it models anything from the real-world, so the resultant figures are likely to be meaningless.
Vasialek
Vasialek
I would say that memory allocation depends on "memory allocation list". If u allocating & freeing lot of 1Mb blocks, then it will take ( probably ) more time for finding enough space for 10Mb block. This is because, system will scan ( probably ) all pointers to free memory blocks & if all memory is consists of 1Mb blocks OS should unit them in one. Realloc() is trying to defragment memory, so sometimes it is good idea to use it

I''m not 100% sure for windows, but in DOS it was working this way...

Lekha
SwSh
SwSh
Ok, you''re right. But it was only to show the order of magnitude.
Oh well, I''ve made another test and it took the computer about 4700ms to calculate 1000000000 sqrt''s. (with doubles)
(I had to put one _asm{nop} inside the loop, but it doesn''t slow down so much)

===========================
UNKNOWN caused an invalid page fault in module unknown at 0000:bff80eb6
: win98 with multiple sclerose

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.