[R] fast mkChar

Duncan Murdoch dmurdoch at pair.com
Tue Jun 8 22:32:36 CEST 2004


On Tue, 8 Jun 2004 12:23:58 -0700, "Vadim Ogranovich"
<vograno at evafunds.com> wrote :

>Hi,
> 
>To speed up reading of large (few million lines) CSV files I am writing
>custom read functions (in C). By timing various approaches I figured out
>that one of the bottlenecks in reading character fields is the mkChar()
>function which on each call incurs a lot of garbage-collection-related
>overhead.
> 
>I wonder if there is a "vectorized" version of mkChar, say mkChar2(char
>**, int length) that converts an array of C strings to a string vector,
>which somehow amortizes the gc overhead over the entire array?
> 
>If no such function exists, I'd appreciate any hint as to how to write
>it.

It's not easy.  Internally R strings always have a header at the
front, so you need to allocate memory and move C strings to get R to
understand them.  

Duncan Murdoch




More information about the R-help mailing list