![]() |
|
#1
|
|||
|
|||
|
GlobalAlloc()
There i have an small problem:
I need allocate many small chunks of memory - i use GlobalAlloc(), the allocated mem. pointers i collect in array - and after using for freeing i call GlobalFree() for all pointers collected in this array - all is good until i use less than 16384 pointers , if i use more , i see message : "system resources exhausted" or something similar. Any solulutions ? |
|
#2
|
|||
|
|||
|
How about using VirtualAlloc instead?
Or have you any special reason why GlobalAlloc has to be used? |
|
#3
|
|||
|
|||
|
why do you have to allocate so many small chunks?
cant you just pre-alloca te bigger chunks and make up your array of pointers like allocate big buff; for(i=0; i<unameit; i++) pointer[i] = buff + i*20; cheers koyaan |
|
#4
|
|||
|
|||
|
While I would echo what everyone has said, I would also like to point out you didn't give enough information, such as what OS your running, what your parameters are to GlobalAlloc, and how much actual memory you have in your machine.
But first, the obvious. If your allocating handles, make sure you realise that they are a FINITE resource per process. Second, if you allocate lots of VirtualAllocs, please understand they always start on a page boundry, and you have only 2GB of process space you can map it into (i.e. lots of little VirtualAllocs will eat into your address space pretty fast). Same is true for threads. I can't tell you how many times I've ran into situations where someone says "I can only get just under 2000 threads". Did you check where ESP was pointing on thread entry? It's about a meg higher than the previous thread, isn't it? Decrease the thread stack size so the computer can map it in! Duh! Anyway, need more info. |
|
#5
|
|||
|
|||
|
Thanx all
![]() Problem resolved with allocation big table and array of pointers - as koyaan says.These "chunks" are allocated structures in an symbol table - the part of compiler. Regards. Janus. |
|
#6
|
|||
|
|||
|
@gigaman:
About VirtualAlloc: dwSize in: Size of the region, in bytes. If the lpAddress parameter is NULL, this value is rounded up to the next page boundary. Otherwise, the allocated pages include all pages containing one or more bytes in the range from lpAddress to (lpAddress+dwSize). This means that a 2-byte range straddling a page boundary causes both pages to be included in the allocated region. so even if you allocate 1-byte using virtualAlloc, the system will reserve an entire page (4KB). |
|
#7
|
|||
|
|||
|
I know - but the original post didn't say how big these "chunks" are. I was just trying to get some more information. Of course, allocating a bigger piece of memory and doing your own handling of smaller memory allocation is better, just requires some additional work.
Btw, even for GlobalAlloc the documentaion says that bigger piece of memory than the requested one may be allocated. |
|
#8
|
|||
|
|||
|
MSDN discourages the use of GobalAlloc
maybe you should use the heap functions hxxp://msdn.microsoft.com/library/en-us/memory/base/heap_functions.asp |
![]() |
|
|