Jump to content

  • Log In with Google      Sign In   
  • Create Account


Can't allocate memory for DB or BMP


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 t3rr0r   Members   -  Reputation: 122

Like
Likes
Like

Posted 05 October 1999 - 12:47 AM

I use Borland C++ 3.1/DOS, large memory, 300MHZ, 64MB. Technically, why would malloc return NULL? I'm trying to allocate memory for the double buffer (64000 bytes) and .bmps (usually 800). malloc fails more times than it succeeds, even with small .bmps and no DB. If it does succeed, the program crashes. Why?

Sponsor:

#2 SPR   Members   -  Reputation: 122

Like
Likes
Like

Posted 04 October 1999 - 10:22 PM

This is because you are using DOS real mode.
In this case it does not matter how much physical memory you have (64 MB or 128 MB or more), you can only use 1MB, and this 1MB is segmented. You have to declare the pointers pointing to the memory buffer with the "far" keyword:

//Declaring the pointer pointing to the //memory buffer

unsigned char far*bufferptr;

//Allocating 64000 bytes:

bufferptr=(unsigned char far*)malloc(64000*sizeof(unsigned char));

This code allocates 64000 bytes in the far heap, which size is about 400-500 Kbyte, so if you want to allocate big memory, you have to use the "far" keyword. Without it, the program tries to allocate the memory in the data segment, which is 64Kbyte large.

I hope this could help you, but I suggest forgetting the DOS and Real mode,and start to develop in Windows Protected mode. Belive me, in this case you can allocate as much memory as you need, and you can use easily the malloc() function.


#3 CJ   Members   -  Reputation: 122

Like
Likes
Like

Posted 05 October 1999 - 12:47 AM

Hmm, in windows I would recommend using the new operator, since they use malloc, and check the return value....

------------------
Dance with me......





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS