[Rd] memory allocation questions
Mark.Bravington at csiro.au
Mark.Bravington at csiro.au
Tue Sep 14 01:38:55 CEST 2004
Dear R-devel
This one seems a bit arcane for R-help. I very often use R to call routines written in Delphi (son of Pascal), doing "persistent" memory allocation within Delphi. That is, I start R and load the Delphi DLL; then I use .C to call a Delphi routine which allocates a piece of memory X and returns to R a pointer to X; then I do some more stuff in R; then I call another Delphi routine, passing it the pointer to X. Finally, I call another Delphi routine from R to free the memory at X.
For years, I've used Delphi's own memory manager for this (the basic one, not SHAREMEM.DLL), but recently I've been wondering whether it would be better to use R's wrappers for "alloc" etc. instead. The Delphi routines seem generally to work fine, but my nagging concern [based on ignorance] is whether R's memory manager will somehow not realize that Delphi has already allocated the memory, and will overwrite it inadvertently. It's fairly easy to replace Delphi's manager with the R routines, following the instructions in section 5.1.2 of R-EXTS and the Delphi manual. So my first question is:
should I bother using the R routines instead?
My second question is:
if I do use the R replacements, what are their names nowadays?
R-EXTS refers to Calloc, Realloc and Free, but these aren't exported by R.DLL (for R1.9.0 or 1.9.1) and I couldn't find mention of any name change in the NEWS file. Running
dumpbin /exports R.dll | find /i "alloc"
suggests either "memalloc/memrealloc/memfree" or "Rm_alloc..." (or "R_chk_alloc..."). I gather that the S_alloc family is intended for temporary allocations that are cleared at the end of the the .C call.
Any insights appreciated. FWIW I use Windows 2000 and Delphi 6.
Mark
*******************************
Mark Bravington
CSIRO (CMIS)
PO Box 1538
Castray Esplanade
Hobart
TAS 7001
phone (61) 3 6232 5118
fax (61) 3 6232 5012
Mark.Bravington at csiro.au
More information about the R-devel
mailing list