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.
unsigned char far *Buffer=new unsigned char[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.
void memset16(unsigned char far *Buffer,unsigned int length)
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.