One point more for supporting the idea of Cython handling this automatically in the future!!. He have to malloc and perhaps memalign for generating temporary buffers. I forgot to mention the memalign issue because GNU systems automatically do that for you.
On 4/12/08, Martin C. Martin <[EMAIL PROTECTED]> wrote: > > > Robert Bradshaw wrote: > > > On Apr 12, 2008, at 4:09 PM, Lisandro Dalcin wrote: > > > > > > > I've just realized that using a string or buffer object for automatic > > > management of memory as I proposed has a pitfall: memory alignement is > > > not guaranteed. > > > > > > So perhaps the only way to go is with this trick is to use a custom > > > python object internally calling malloc/free. > > > > > > > It looks like strings are aligned on int boundaries (given their struct). > > > > On 64 bit machines, gcc uses 32 bits for ints, so simply aligning on int > boundaries wouldn't get you 64 bit aligned. > > > > What guarantee does one have about malloc? > > > > It depends on the implementation. For glibc: > > http://www.gnu.org/software/libc/manual/html_node/Aligned-Memory-Blocks.html#Aligned-Memory-Blocks > > "The address of a block returned by malloc or realloc in the GNU system is > always a multiple of eight (or sixteen on 64-bit systems)." > > You could always do what memalign() does: if e.g. you need something > aligned on 8 byte boundaries, but Python's string allocation only uses 4 > byte boundaries, then allocate an extra 4 bytes, and if the result isn't 8 > byte aligned, return the address + 4. > > > > I would imagine we would have a custom object (which would be very > simple) and even faster than a stringobject. > > > > Best, > Martin > -- Lisandro Dalcín --------------- Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC) Instituto de Desarrollo Tecnológico para la Industria Química (INTEC) Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET) PTLC - Güemes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
