[racket-dev] proposed doc change on memset docs

From: John Clements (clements at brinckerhoff.org)
Date: Tue Aug 24 07:33:07 EDT 2010

The ffi's "memset" operation takes an optional "type" argument, but it's not clear what happens if the type isn't _byte.  Here are the docs:

(memset cptr byte count [type]) → void?
  cptr : cpointer?
  byte : byte?
  count : exact-nonnegative-integer?
  type : ctype? = _byte
(memset cptr offset byte count [type]) → void?
  cptr : cpointer?
  offset : exact-integer?
  byte : byte?
  count : exact-nonnegative-integer?
  type : ctype? = _byte

Similar to memmove, but the destination is uniformly filled with byte (i.e., an exact integer between 0 and 255 inclusive).


So, if I run this code:

#lang racket

(require ffi/unsafe
         ffi/cvector)

(define buf (cvector _float 0.0 0.0 0.0 0.0))

(memset (cvector-ptr buf) #x13 4 _float)

(cvector->list buf)

... it's not obvious from the docs whether I'm going to get memory containing

#x13131313131313131313131313131313

or

#x13000000130000001300000013000000

(or some other endian-ness).

Based on my experiments, the answer is the former; that is, a type is simply used to multiply the number of bytes that need to be set.

Okay then to modify the docs as follows?

"Similar to memmove, but the destination is uniformly filled with byte (i.e., an exact integer between 0 and 255 inclusive). If a "type" argument is present, the result is the same as calling memmove with no type argument where the count multiplied by the size in bytes of the given type."

Klunky, but gets the job done.

John




-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4669 bytes
Desc: not available
URL: <http://lists.racket-lang.org/dev/archive/attachments/20100824/17a1a15d/attachment.p7s>

Posted on the dev mailing list.