[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] binary data
From: |
felix winkelmann |
Subject: |
Re: [Chicken-users] binary data |
Date: |
Tue, 12 Sep 2006 08:32:36 +0200 |
On 9/11/06, john <address@hidden> wrote:
Hi!
Is there an efficient way to retrieve some binary data from C into
Chicken so that I could then read and write the data over a network
using Chicken rather than using the FFI? The data I have allocated in
C may contain nulls so I am not able to bring it over as a c-string. I
have noticed the move-memory! command and wonder if this would do the
trick if I moved the data to a byte-vector, or am I barking up the
wrong tree and better off sticking with the FFI? Also, what is
difference between primitive byte-vectors and SRFI-4 byte vectors?
You can do two things, depending on your needs:
- If you want the data to be garbage-collectable, you should allocate
a byte-vector and move-memory! the data from a raw pointer
that you pass to Scheme into the byte-vector.
- If you have control over the creation of the binary data, you can
simply add a byte-vector header (1 word) at the front (that would
be a C_word containing (C_BYTEVECTOR_TYPE | <size in bytes>).
Passing the pointer to the word (which should be 8-byte aligned and be
followed by the actual data) to scheme as a scheme-object lets
you treat it like any other Scheme data, but it won't be GCd.
SRFI-4 byte-vectors are internally just structures containing a byte-vector
(and a structure tag).
cheers,
felix
--
http://galinha.ucpel.tche.br:8081/blog/blog.ssp