offscreen= (char *) farmalloc(64000u);
_fmemset(offscreen,0,64000u);
i've tried to debug and after executing the _fmemset statement it crashes
Printable View
offscreen= (char *) farmalloc(64000u);
_fmemset(offscreen,0,64000u);
i've tried to debug and after executing the _fmemset statement it crashes
why does farmalloc always return NULL in my comp ?
1. have you prototyped it by including the right .h file
2. remove the cast - a) its broken, b) its not needed
(char far*) would be better
3. is offscreen also declared as a far pointer
4. why are you still messing around in the stone age?
Salem, do u have a better solution ?, what i intend to is to allocate memory above 64K , and the only thing i know is using farmalloc
First of all you need to check to make sure that farmalloc did in fact allocate memory. If it did not, then your fmemset will be trying to set memory via a null pointer which will crash because the pointer could be pointing at anything.
I don't use the *allocs.
This should work.Code:
unsigned char far *Buffer=new unsigned char[64000L];
memset(Buffer,0,64000L);
A faster method in 16-bit DOS though is this. This is inline assembly.
But it will not work within the IDE for DOS programs, only in Borland for Windows. The IDE in DOS takes up too much RAM so this will always return a null pointer. This means that your code must be tested from the command line and not from within the IDE. Borland C/C++ for Windows does not suffer from this problem.Code://16-bit memset
void memset16(unsigned char far *Buffer,unsigned int length)
{
asm {
cld //set to increment for DI
les di,Buffer //load full pointer in es:di
mov cx,length //set for length
shr cx,1 //convert from bytes to integers
mov al,0 //set al to 0
mov ah,0 // set ah to 0 -> mov ax,0000h
rep stosw //store ax in ES:DI for CX length, inc DI
}
}
The asm code will transfer words instead of bytes. So it will transfer 16 bits of information per iteration instead of 8. A faster method would be stosd, but you would have to do some operand overrides to get it to work. I left it out because it would only confuse you.