maximal memory allocation using malloc 
Author Message
 maximal memory allocation using malloc

I have a P4 with 1.5Gb memory running XP with VC++ 7.0. I am using a C
procedure in a C++ program. The C procedure uses malloc to iteratively
allocate rather large chunks of memory (280000 bytes) and in each iteration
it also frees it again. At some point malloc returns a null pointer meaning
it cannot allocate the requested amount of memory. However, I have observed
using the task manager that the process only uses about 250Mb of memory when
this occurs (and this proces is the only one running besides system
processes). Now my question is why do I get an out of memory error when I
have only used 250Mb of 1.5Gb and only require additional 280Mb?

Is there some setting in VC++ where you can specify how much memory a
program is allowed to allocate? or is it because I am using malloc in a C++
program?

Thanks very much for any assistance regarding this,
Brian




Mon, 28 Feb 2005 04:06:57 GMT  
 maximal memory allocation using malloc
Where is the process running?  I read somewhere that there is a limit as to
how much memory is available to processes that run in the kernel.

MattC


Quote:
> I have a P4 with 1.5Gb memory running XP with VC++ 7.0. I am using a C
> procedure in a C++ program. The C procedure uses malloc to iteratively
> allocate rather large chunks of memory (280000 bytes) and in each
iteration
> it also frees it again. At some point malloc returns a null pointer
meaning
> it cannot allocate the requested amount of memory. However, I have
observed
> using the task manager that the process only uses about 250Mb of memory
when
> this occurs (and this proces is the only one running besides system
> processes). Now my question is why do I get an out of memory error when I
> have only used 250Mb of 1.5Gb and only require additional 280Mb?

> Is there some setting in VC++ where you can specify how much memory a
> program is allowed to allocate? or is it because I am using malloc in a
C++
> program?

> Thanks very much for any assistance regarding this,
> Brian





Mon, 28 Feb 2005 09:08:33 GMT  
 maximal memory allocation using malloc


Quote:
> I have a P4 with 1.5Gb memory running XP with VC++ 7.0.

The amount of available physical memory has nothing to do (or very
indirectly) with how much memory a process can claim. Each process has 2 GB
available to store all it's stuff (code, data, stack, ....).
If a memory allocation request fail, it can be :
- Because there is no more physical memory available (RAM + swap), but
Windows will popup a dialog box "The system is short of virtual memory
......." before it occurs, and even before that it will try to accomodate by
extending the swap file(s).
- Because the 2 GB process virtual adress space is full (for example if you
map some very big files onto the process space).
- Because the virtual adress space is to much fragmented and there is no big
enough free chunck to meet your requirement.

Quote:
> I am using a C
> procedure in a C++ program. The C procedure uses malloc to iteratively
> allocate rather large chunks of memory (280000 bytes) and in each
iteration
> it also frees it again. At some point malloc returns a null pointer
meaning
> it cannot allocate the requested amount of memory.

Are you sure the memory is freed? Isn't there some memory allocation
somewhere else? You should use a tool such as purify to track down your
leak.

Arnaud
MVP - VC



Mon, 28 Feb 2005 17:14:42 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Memory allocation using malloc

2. memory allocation using malloc and free

3. Tree memory allocation, pool memory allocation

4. Need help with dynamic memory allocation (malloc) in C

5. malloc memory allocation checking tool wanted

6. dynamic memory allocation performance problems with malloc/free

7. Help of Malloc--problem of memory allocation

8. Memory allocation, malloc, GlobalAlloc, VirtalAlloc, HeapAlloc.

9. a very strange memory allocation problem, malloc vs new

10. Two dimensional dynamic allocation using malloc

11. Multi-dimensional array using dynamic memory allocation

12. Binary Search Tree using dynamic memory allocation (URGENT request for example)

 

 
Powered by phpBB® Forum Software