www.digitalmars.com         C & C++   DMDScript  

c++.windows.16-bits - hcalloc

reply Mark Evans <mevans zyvex.com> writes:
You might consider adding this function to the runtimes.

In 16-bit runtimes, huge pointers may be allocated and freed.  What is lacking
is an equivalent of calloc which clears the memory when it is allocated.

Here's my version.


void __huge *_hcalloc(long num, size_t size)
{
	char __huge *data;
	unsigned long int actual_bytes,i;
	
	data = _halloc(num,size);
	
	if (data != NULL)
	{
		actual_bytes = num * size;
		for(i=0;i<actual_bytes;i++)
			*data++ = 0;
	}
	return data;
}




Mark
Jun 21 2001
parent Mark Evans <mevans zyvex.com> writes:
Sorry, make that:


// Digital Mars runtime lacks a calloc-style function for huge pointers
void __huge *_hcalloc(long num, size_t size)
{
    void __huge *data;
    char __huge *clearptr;

    unsigned long int actual_bytes,i;
    
    data = _halloc(num,size);

    if (data != NULL)
    {
        clearptr = data;
        actual_bytes = num * size;
        for(i=0;i<actual_bytes;i++)
            *clearptr++ = 0;
    }

    return data;
}
Jun 21 2001