From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Allocating a C string without heap
Date: Sat, 26 Jul 2014 18:20:19 +0200
Date: 2014-07-26T18:20:19+02:00 [thread overview]
Message-ID: <o6kl3odqvxa4.yun7qbyg5ry3.dlg@40tude.net> (raw)
In-Reply-To: lr0jcd$je3$1@speranza.aioe.org
On Sat, 26 Jul 2014 19:01:20 +0300, Victor Porton wrote:
> Let we have an Ada String.
>
> I need to pass it converted to a C string into a C library function.
>
> Now I do it with Interfaces.C.Strings.New_String. But it is slow as it uses
> the heap and requires (not to forget incidentally!) further
> Interfaces.C.Strings.Free.
>
> Is there a better way to do this? I mean that we would probably create a
> nul-terminated char_array (not on the heap but on the stack!) and pass the
> pointer to its first element.
The canonical method is this (Ada 95):
procedure Foo (Text : String) is
procedure Internal (Text : char_array);
pragma Convention (C, Internal, "foo");
begin
Internal (To_C (Text));
end Foo;
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2014-07-26 16:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-26 16:01 Allocating a C string without heap Victor Porton
2014-07-26 16:20 ` Dmitry A. Kazakov [this message]
2014-07-26 16:30 ` Victor Porton
2014-07-26 18:38 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox