chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] working with bit- and byte-level structures


From: Martin DeMello
Subject: [Chicken-users] working with bit- and byte-level structures
Date: Wed, 16 Apr 2008 10:38:17 -0700

Interesting post on one of the advantages of C++ - I just wondered how
such problems are handled in the scheme world

------------------------------------------------------------------------------------------------------
What you can do in C++ that you *can't* do in Java is define a class
whose in-memory representation maps directly to the format of data in
memory, and then say "I want to treat this large swath of memory as if
it were an array of Foo objects" - and gain all of the abstraction of
calling object methods on that data, with zero performance penalty for
instantiating thousands of objects.

It's not something you want to do every day, but on the rare occasion
you need it, C++ comes closest to letting you have your cake and eat
it too.

-- Avdi Grimm on the pragmaticprogrammers mailing list
------------------------------------------------------------------------------------------------------

I ran into this exact problem when trying to access a packed C data
structure from OCaml - I had to write a bunch of code to index into
the block, pull out a chunk of bytes and then write accessor functions
to do bitshifting and bitmasking to retrieve the individual members
from the struct, without much "higher level" help from OCaml. I'm
imagining some combination of C and chicken would do a nicer job of
this, and naturally I'd want to do it with as little C as possible. I
found http://chicken.wiki.br/packedobjects but I couldn't tell if it
could work directly with a block of memory or it there'd be a lot of
from/to overhead.

martin




reply via email to

[Prev in Thread] Current Thread [Next in Thread]