From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: Victor Porton Newsgroups: comp.lang.ada Subject: Re: Allocators design flaw Date: Sat, 14 Oct 2017 19:38:08 +0300 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: 8U0x309/ia0QUzusgm/krA.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/4.14.10 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:48473 Date: 2017-10-14T19:38:08+03:00 List-Id: Simon Wright wrote: > Victor Porton writes: > >> As far as I understand, it will not work, because the C library I am >> writing bindings for may try to free an object allocated by me (or I >> my need to free an object allocated by the library). > > This vital info wasn't part of your original problem statement. > > I suppose you might just get away with creating a storage pool backed up > by raptor_alloc_memory() (and corresponding free). But you'd have to > cope with the alignment issue as Dmitry has suggested. > > Is the Ada side meant to understand things allocated on the C side? If > so, you'll need to specify the representation exactly. > > Is the C side meant to understand things allocated on the Ada side? > Likewise (and no room for hidden dope vectors!) Yes, both sides need to understand struct layout. This is not a trouble at all: I just add Convention=>C to the record. We can know the alignment of the struct (just T'Alignment). The trouble is that Ada may request allocator to allocate with alignment a (nonzero) natural number times more than T'Alignment. This may fail as the requested alignment in principle can be greater than the real alignment the C *_alloc() function does. This is a real trouble. -- Victor Porton - http://portonvictor.org