c++ - malloc return NULL when coreleft()<10000
- veb (5/5) Apr 07 2010 Hello,
- veb (8/8) Apr 08 2010 Hello,
- Walter Bright (4/5) Apr 08 2010 This could very well be a pointer bug in your program, which is difficul...
- veb (9/12) Apr 09 2010 I made another test:
- Walter Bright (5/17) Apr 09 2010 The default is the best size for _stack.
- veb (12/16) Apr 17 2010 Ok,
- Walter Bright (4/24) Apr 17 2010 Looking in Watcom's source code won't help much, should look in Digital
Hello, I have a problem with malloc and realloc. When coreleft is under 9500 bytes, malloc return NULL. my parameters to compile are: -2 -Pz -Jm -R -Ab -msd -o+space -Nc -Ns main.c Thanks to help me to resolve the problem.
Apr 07 2010
Hello, I made some new test: coreleft, stackavail and _chkstack return a value >8000 and _heapchk return -2 (_HEAPOK) BUT _memavl() doesn't return anything, and the programm doesn't respond (and I need to reset everything) I hope this test will help to resolve my problem
Apr 08 2010
veb wrote:I hope this test will help to resolve my problemThis could very well be a pointer bug in your program, which is difficult to resolve in the -ms memory model. What I do is thoroughly debug a program first in 32 bit mode, then try porting it to 16 bits.
Apr 08 2010
Walter Bright wrote:This could very well be a pointer bug in your program, which is >difficult to resolve in the -ms memory model. What I do is thoroughly debug a >program first in 32 bit mode, then try porting it to 16 bits.I made another test: I affected a different value to unsigned __cdecl _stack When it is too small, Some operations don't work, but I can allocate more memory than if _stack is bigger. Which size is best for _stack ? (or how allocate in _stack ?) How to calculate exactly how many memory I can still allocate when the programm runs? (since memavl() doesn't work) Thanks
Apr 09 2010
veb wrote:Walter Bright wrote:The default is the best size for _stack. At the level you're working at, I suggest studying the source code for malloc(), etc. It isn't too complicated, and when you're trying to fit things in 64K it helps a lot to understand the details all the way down.This could very well be a pointer bug in your program, which is >difficult to resolve in the -ms memory model. What I do is thoroughly debug a >program first in 32 bit mode, then try porting it to 16 bits.I made another test: I affected a different value to unsigned __cdecl _stack When it is too small, Some operations don't work, but I can allocate more memory than if _stack is bigger. Which size is best for _stack ? (or how allocate in _stack ?) How to calculate exactly how many memory I can still allocate when the programm runs? (since memavl() doesn't work)
Apr 09 2010
Walter Bright wrote:The default is the best size for _stack. At the level you're working at, I suggest studying the source code for malloc(), etc. It isn't too complicated, and when you're trying to fit things in 64K it helps a lot to understand the details all the way down.Ok, I look for malloc's source in the sources of open watcom, and I don't really realize why _stack needs to be big. I would like to reduce the size of _stack, and I would instead alloc many time a small buffer with malloc to alloc a big buffer (will it work?) For example if I write unsigned __cdecl _stack=2048; and would like to allocate a 1024 bytes buffer, should I write: "buffer=realloc(buffer,500); buffer = realloc(buffer,1024);" instead of"buffer=realloc (buffer,1024);" ? Thanks for your help
Apr 17 2010
veb wrote:Walter Bright wrote:Looking in Watcom's source code won't help much, should look in Digital Mars' sources.The default is the best size for _stack. At the level you're working at, I suggest studying the source code for malloc(), etc. It isn't too complicated, and when you're trying to fit things in 64K it helps a lot to understand the details all the way down.Ok, I look for malloc's source in the sources of open watcom, and I don't really realize why _stack needs to be big.I would like to reduce the size of _stack, and I would instead alloc many time a small buffer with malloc to alloc a big buffer (will it work?) For example if I write unsigned __cdecl _stack=2048; and would like to allocate a 1024 bytes buffer, should I write: "buffer=realloc(buffer,500); buffer = realloc(buffer,1024);" instead of"buffer=realloc (buffer,1024);" ? Thanks for your helpI'd just use 1024.
Apr 17 2010