* Interfacing Generics with C Pointers
@ 2003-03-17 13:56 Brian Palmer
2003-03-17 20:09 ` Robert A Duff
0 siblings, 1 reply; 2+ messages in thread
From: Brian Palmer @ 2003-03-17 13:56 UTC (permalink / raw)
I've got a problem where I get in a pointer to a block of memory that was
allocated in C++. In addition to the pointer, I get the number of bytes
that were allocated. The Ada type that the memory comes in as is a pointer
to an unconstrained byte array. Whenever I try to dereference the pointer,
I get a CONSTRAINT ERROR. I think the problem is due to the compiler
trying to access a storage location within the type that tells how many
bytes are there. I feel like I could constrain the base type and get
around the problem, however, this mechanism is used for several different
size blocks of memory, several hundred times per second, and I don't want
to have to allocate more memory than necessary. Any ideas how to access
unconstrained memory without the compiler looking for that built in
element?
Any help would be appreciated.
-Brian Palmer
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Interfacing Generics with C Pointers
2003-03-17 13:56 Interfacing Generics with C Pointers Brian Palmer
@ 2003-03-17 20:09 ` Robert A Duff
0 siblings, 0 replies; 2+ messages in thread
From: Robert A Duff @ 2003-03-17 20:09 UTC (permalink / raw)
Brian Palmer <bpalmer@elmco.com> writes:
> I've got a problem where I get in a pointer to a block of memory that was
> allocated in C++. In addition to the pointer, I get the number of bytes
> that were allocated. The Ada type that the memory comes in as is a pointer
> to an unconstrained byte array. Whenever I try to dereference the pointer,
> I get a CONSTRAINT ERROR. I think the problem is due to the compiler
> trying to access a storage location within the type that tells how many
> bytes are there.
Probably true. In general, unconstrained arrays don't work well when
interfacing to C, because C doesn't know about the dope.
>... I feel like I could constrain the base type and get
> around the problem, however, this mechanism is used for several different
> size blocks of memory, several hundred times per second, and I don't want
> to have to allocate more memory than necessary. Any ideas how to access
> unconstrained memory without the compiler looking for that built in
> element?
One way is to lie to the Ada compiler about the length of the array.
E.g., "type T is array(Natural) of ...;" then you get back a pointer to
T, and you can refer to X.all(I). Just make sure I doesn't go out of
the "real" ounds. Presumably the real bounds are available via some
other means.
As soon as possible, start dealing with the data in a safer way -- e.g.,
pass the appropriate slice of X.all off the to rest of the code.
- Bob
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-03-17 20:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-17 13:56 Interfacing Generics with C Pointers Brian Palmer
2003-03-17 20:09 ` Robert A Duff
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox