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:42:50 +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:48474 Date: 2017-10-14T19:42:50+03:00 List-Id: Dmitry A. Kazakov wrote: > On 2017-10-14 17:18, Victor Porton wrote: >> Dmitry A. Kazakov wrote: >> >>> On 2017-10-14 16:03, Victor Porton wrote: >>>> Dmitry A. Kazakov wrote: >>>> >>>>> When freed use the stored offset to > ^^^^^^^^^^^^^^^^^^^^^^^^ >>>>> get the original address. > ^^^^^^^^^^^^^^^^^^^^^^^^ > >>>> 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). >>> >>> The last sentence describes freeing memory, i.e. for Deallocate. >> >> I again state that we need the C function *_free() to free memory. But it >> is impossible in your scenario, because you change the pointer to point >> to another byte of memory. > > Re-read the last sentence of my response. No Dmitry, you don't understand me. We may pass the allocated address to a C function. 1. This C function may need to get some data from the struct. In this case we need to pass into C the shifted address. 2. This C function may call *_free() with the address of the struct. In this case we need to pass into C the original allocation address. Thus the same address we pass into a C function is both original and shifted. This is a clear contradiction. -- Victor Porton - http://portonvictor.org