[S] <sapi/malloc.h>

Jonathan Higa (higa@math.hawaii.edu)
Thu, 14 May 1998 12:15:03 -1000


Preferring C++ to C, I've had problems using Calloc and Free because
<S_ansi.h> defines Calloc to call S_ok_calloc, but S_ok_calloc is
prototyped as
char *S_ok_calloc();
which in C++ is the same as
char *S_ok_calloc(void);
causing nasty problems when one tries to call it with two arguments.
Instead of editing <S_ansi.h>, inspecting <sapi/malloc.h> seemed
simpler. So...

I would appreciate some suggestions on how to use <sapi/malloc.h>
properly. The comments therein are quite helpful, but not conclusive.
Consider the following code, for the inquiries that follow:

// begin code fragment
#include <sapi/malloc.h>

void *operator new(size_t n) throw()
{
S_apiMallocTypeFlags t = S_apiSetMallocType(S_API_MALLOC_INTERNAL);
void *p = S_apiMalloc(n);
S_apiSetMallocType(t);
return p;
}

void operator delete(void *p) throw()
{
if (p)
S_apiFree(p);
}
// end code fragment

First, is it safe to use SAPI this way? The documentation for S
discusses only the use of Calloc, Free, S_alloc, and other similar
functions.

Second, can S_apiMalloc ever return NULL? (Does S_apiMalloc handle
allocation errors?)

Finally, if there are related unaddressed issues, please feel free to
offer comments.

Jonathan Higa, higa@math.hawaii.edu, S+ user

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news