[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C w/ malloc in/from KCL

> I am new to KCL and was looking through the KCL-mail archives to
> find out more on the foreign function interface in KCL. 
> In particular, I am interested in knowing what extra work (if at all) 
> has to be done to use the foreign function interface with a C-code 
> that probably has its own memory manager (or that could use malloc).

KCL provides it's own version of malloc.  However, some versions at
least (maybe all of them) fail to provide valloc and memalign.
Some code that used to work for this purpose (I haven't tested it
in recent versions of AKCL) is:

extern object malloc_list;

char *
memalign(alig, size)
int alig, size;
	object x;
	char *bigblock, *actual;

	bigblock = alloc_contblock(size+alig);
	actual = (char *)((int)(bigblock+alig-1) & ~alig);
	insert_contblock(bigblock, actual-bigblock);
	insert_contblock(actual+size, alig-(actual-bigblock));
	x = alloc_simple_string(size);
	x->st.st_self = actual;
	malloc_list = make_cons(x, malloc_list);

char *valloc(size)
int size;
    return memalign(getpagesize(), size);


The idea is that you can add the above to your code to take over
calls to valloc and memalign.

I'm not sure what to do about code that has a memory manager
completely its own.

Jeff Dalton,                      JANET: J.Dalton@uk.ac.ed             
AI Applications Institute,        ARPA:  J.Dalton@ed.ac.uk
Edinburgh University.             UUCP:  ...!ukc!ed.ac.uk!J.Dalton