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.
Code:
unsigned char far *Buffer=new unsigned char[64000L];
memset(Buffer,0,64000L);
This should work.
A faster method in 16-bit DOS though is this. This is inline assembly.
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
}
}
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.
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.