Allocation memory

Started by
27 comments, last by kitkit 15 years, 9 months ago
Quote:Original post by glaeken
Also, just because you have 1.5 GB of memory does not mean that all of that is available for user space applications. A portion of your memory is devoted to kernel space applications.
Not exactly; a portion of the address space is. Anything above 0x80000000 is reserved for the kernel which is the important thing. You could have 256MB of RAM and allocate a 1GB chunk of memory without any problems (Apart from it'll be slow as hell [smile])
Advertisement
You, know, may be you are right, but I returned to old problem when I try to allocate 40mb. At this moment I have about 1.3gb free but, when I try to allocate 40mb I have old error :( . BUT !! when I, at this moment try to allocate four times by ten mb I have no error!!! I know, you should tell me that I have memory fragmentation. But I have 1.3gb free!!!!!!!!!!!! what can you say ?
----------------------

kit

Quote:Original post by kitkit
You, know, may be you are right, but I returned to old problem when I try to allocate 40mb. At this moment I have about 1.3gb free but, when I try to allocate 40mb I have old error :( . BUT !! when I, at this moment try to allocate four times by ten mb I have no error!!! I know, you should tell me that I have memory fragmentation. But I have 1.3gb free!!!!!!!!!!!! what can you say ?
How do you know you have 1.3GB free? What if you call VirtualAlloc(NULL, 40*1024*1024, MEM_COMMIT | MEM_RESERVE, 0);? That's the lowest level allocation function you can possibly get. If it returns null, then you simply don't have enough free unfragmented memory.

It's also possible that you have heap corruption going on, which could break the CRT allocator and cause allocations to fail.
I have to mention that I ckecked app for leaks - there are no leaks.
----------------------

kit

Evil Steve , thanks you! I can say that with this method I have no warnings, leaks or errors. Now my app works correctly.

What you can say now? Why didn't works it before?? Can you say?
----------------------

kit

Quote:Original post by kitkit
Evil Steve , thanks you! I can say that with this method I have no warnings, leaks or errors. Now my app works correctly.

What you can say now? Why didn't works it before?? Can you say?
That's odd... I'd avoid using VirtualAlloc if possible, it's a bit too low level to be using normally. It looks like heap corruption to me, but I could be wrong. Basically, I don't know [smile]
Maybe he is making the largest ASCII MMO ever and the world is mapped in a 1.5BG char array?
Let's continue our discussion. I have founded that real exception throws on string

_munlock(_HEAP_LOCK);

in file

dbgheap.c


in method

void * __cdecl _nh_malloc_dbg

Can you help me again ??
----------------------

kit

I seem to recall that's the internal function that actually does the memory allocation. If you trace into the memory allocation call, you should find out the reason it fails (E.g. VirtualAlloc fails or something). I'll try doing this myself at my lunch break (2 hours time).
May I write "call stack" output to this forum ?


kernel32.dll!7c812aeb()
kernel32.dll!7c812aeb()
msvcr71d.dll!_nh_malloc_dbg(unsigned int nSize=1, int nhFlag=3, int nBlockUse=14466340, const char * szFileName=0x00dcbe9c, int nLine=14466728) Line 267 + 0x7 C
msvcr71d.dll!_CxxThrowException(void * pExceptionObject=0x00dcbd40, const _s__ThrowInfo * pThrowInfo=0x104f6150) + 0x39 C++
msvcp71d.dll!std::_Nomemory() Line 10 C++
test_appD.exe!operator new(unsigned int size=40981387) Line 15 C++
> test_appD.exe!operator new[](unsigned int count=40981387) Line 7 + 0x9 C++
----------------------

kit

This topic is closed to new replies.

Advertisement