This is the mail archive of the
mailing list for the Guile project.
Confusion on scm_make_smob_type
- To: firstname.lastname@example.org
- Subject: Confusion on scm_make_smob_type
- From: Lars Arvestad <email@example.com>
- Date: 31 Aug 1999 15:56:49 +0200
What is the purpose of the size argument in scm_make_smob_type? From
data-rep.info in the distribution:
- Function: long scm_make_smob_type (const char *name, scm_sizet size)
This function adds a new smob type, named NAME, with instance size
SIZE to the system. The return value is a tag that is used in
creating instances of the type. If SIZE is 0, then no memory will
be allocated when instances of the smob are created, and nothing
will be freed by the default free function.
As I understand it, I can make SCM_NEWSMOB allocate my smob, which I
then can fill in, and the mark/free function then work automatically
as long as I don't have pointer to other dynamic memory in the smob?
But in the image example in the same info file, the smob is allocated
manually with scm_must_malloc and handed over to SCM_RETURN_NEWSMOB in
an make_image function:
image = (struct image *) scm_must_malloc (sizeof (struct image), "image");
image->width = width;
image->height = height;
image->pixels = scm_must_malloc (width * height, "image pixels");
image->name = name;
image->update_func = SCM_BOOL_F;
SCM_RETURN_NEWSMOB (image_tag, image);
What's up with that? I guess I still don't understand the whole smob
thingy, although I have used them for quite some time now without
I would really appreciate two very simple examples:
1. An smob for a C struct. No pointers to malloced memory.
2. An smob for a pointer to a malloced C struct.
I know how to do this (or think I do!), but I don't understand what I
can get for free from libguile. What is the most simple way to do
Lars Arvestad Dept. of Numerical Analysis and Computing Science
Royal Institute of Technology (KTH), Stockholm, Sweden