[plt-scheme] Re: large blocks inside cstructs

From: Eli Barzilay (eli at barzilay.org)
Date: Mon Dec 18 00:05:00 EST 2006

On Dec 17, Dave Herman wrote:
> I'm having trouble getting started with foreign.ss. I'm trying to
> define a struct type whose corresponding C definition looks
> something like:
> 
>      typedef struct {
>        ...
>        char AdapterName[260];
>        char Description[132];
>        ...
>      } IP_ADAPTER_INFO;
> 
> I can't figure out how to do the declaration. I thought
> 
>      (define-cstruct _IP_ADAPTER_INFO (...
>                                        [AdapterName (_bytes o 260)]
>                                        [Description (_bytes o 132)]
>                                      ...))
> 
> would do the trick, but it's saying those elements only have a size
> of 4 bytes.

Yes, you get pointers with that.


> How should I do this?  Other than putting 260 / 4 dummy _int32 slots
> in a row, I mean. :)

There's no good solution for that, sorry.  One way would be to
generate dummy slots, which would be a hassle to generate, but will
allow you to address slots conveniently.  Another way is to just use
malloc directly, which is a different kind of a hassle.

(The problem in making something like an embedded memory block
possible is that it should not behave like a pointer -- so some future
solution to this will allow you to set and read stuff from these
blocks, but will not allow you to grab a pointer -- that's something
that will break the 3m collector.  Of course, another solution is to
allow such things only if they're used with non-GC memory, with
everything that it implies.)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.