comp.lang.ada
 help / color / mirror / Atom feed
From: NiGHTS <nights@unku.us>
Subject: Interfaces.C.Strings chars_ptr memory management strategy
Date: Fri, 25 May 2018 15:22:12 -0700 (PDT)
Date: 2018-05-25T15:22:12-07:00	[thread overview]
Message-ID: <6ff31dc6-31e7-4755-bda0-1b53fa02f31f@googlegroups.com> (raw)

I am creating a binding to a C library that requires me to repeat the same function but with a string parameter that changes on each call. I don't want to have to keep creating and destroying string memory for all of these function calls. I would like to create the memory for the string once, allocate enough space so it doesn't need to grow, and reuse that memory for the function call every time I need to pass a new string to it.

The trick here is that whatever strategy I use must be compatible with C, so for instance using a storage pool would not be directly compatible with the C binding.

Here is just a quick and sloppy idea I had on how to tackle my problem.

str : chars_ptr := New_String ("                                     ");
...
Update (Item => str, Offset => 0, Str => "Some Param");
...
Update (Item => str, Offset => 0, Str => "Some Other Param");
...
Free (str);

I find the first line quite ugly. I'm sure there is an easier way to create a large empty string but I can't seem to come up with an elegant way to do it.

As far as the Update commands, will it act like strcpy() in C? If so I'd guess that this is an efficient technique.

Thanks for your help!

             reply	other threads:[~2018-05-25 22:22 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-25 22:22 NiGHTS [this message]
2018-05-26  2:52 ` Interfaces.C.Strings chars_ptr memory management strategy Shark8
2018-05-26 12:44   ` NiGHTS
2018-05-26 13:56     ` Shark8
2018-05-30 13:10 ` Alejandro R. Mosteo
2018-05-30 19:56   ` Randy Brukardt
2018-05-31 10:34     ` Alejandro R. Mosteo
2018-05-31 22:25       ` Randy Brukardt
2018-06-05 12:42         ` Alejandro R. Mosteo
2018-06-03 18:31 ` ytomino
2018-06-03 19:33   ` Dmitry A. Kazakov
2018-06-03 20:03     ` ytomino
2018-06-04  7:06       ` Dmitry A. Kazakov
2018-06-04  7:47         ` ytomino
2018-06-03 20:37     ` ytomino
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox