caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Runtime string allocation/resizing
@ 2005-06-21 20:43 Robert Roessler
  2005-06-21 21:49 ` [Caml-list] " Stephane Glondu
  2005-06-22  0:07 ` Jacques Garrigue
  0 siblings, 2 replies; 3+ messages in thread
From: Robert Roessler @ 2005-06-21 20:43 UTC (permalink / raw)
  To: Caml-list

When dealing with OCaml-to-C-land interfacing, I sometimes am in the 
position of needing to allocate and fill a string - but only have an 
upper bound for the length... until after I have already copied the 
data [from a third-party library function].

What is the recommended "OCaml" way to deal with this?

Should I do two caml_alloc_string calls?  One to initially "get" the 
data, and then alloc a second one and copy to it after I know the 
correct length?

Or would it be considered better practice to use malloc in the C heap 
for the "temp" copy and only do the caml_alloc_string when I know the 
exact size?

Or ?

BTW, I am more concerned with longer-term issues like memory 
fragmentation and "extra" [minor] collections than with raw speed (as 
in copying the data twice being "evil").

Robert Roessler
roessler@rftp.com
http://www.rftp.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-06-22  0:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-21 20:43 Runtime string allocation/resizing Robert Roessler
2005-06-21 21:49 ` [Caml-list] " Stephane Glondu
2005-06-22  0:07 ` Jacques Garrigue

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).