[erlang-questions] sizeof() FFI types

Alceste Scalas <>
Wed Sep 12 10:54:41 CEST 2007


Il giorno mer, 12/09/2007 alle 09.21 +0200, Alceste Scalas ha scritto:
>   * ffi:pointer_to_binary(Pointer, Size) would return a new binary()
>     with a copy of Size bytes read from Pointer.

Well, one may even want to use the data inside the new binary --- and if
it represents a struct or some other complex data type, one may need to
know the sizes of the C basic types in order to perform binary matching.

This additional BIF may be useful:

      * ffi:sizeof(CType): return the number of bytes used by CType on
        the current platform.  CType is one of the supported FFI type
        atoms.

Summing up, this email and the previous one contain the following
additions to the Erlang/OTP FFI proposal available on
http://muvara.org/crs4/erlang/ffi/ :

      * 'cstring' FFI type
      * ffi:cstring_to_binary/1 BIF
      * ffi:pointer_to_binary/2 BIF
      * ffi:sizeof/1 BIF

Based on your feedback, I'll add a patch and update the draft EEP.

Regards,

alceste
-- 
Alceste Scalas <>
CRS4 - http://www.crs4.it/




More information about the erlang-questions mailing list