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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,42a57c8ee023f14d X-Google-Attributes: gid103376,public From: "W. Wesley Groleau (Wes)" Subject: Re: Q: memory management Date: 1996/06/19 Message-ID: <9606192037.AA13484@most>#1/1 X-Deja-AN: 161083005 sender: Ada programming language comments: To: Hannes.Haug@Student.Uni-Tuebingen.de mailer: Elm [revision: 70.85] newsgroups: comp.lang.ada Date: 1996-06-19T00:00:00+00:00 List-Id: :> : But I really just want a pointer to some amount of storage. I have to :> : pass it to som assembly routines. This routines cannot benefit from the :> : bounds in the array representatio. They would even overwrite them. And :> : I have to worry about space. The here useless bounds would cost me at :> : least 1MB. :> :> Does the size vary from one allocation to the next, or :> are they all the same size? If they are all the same size, :> you may declare the access type with a constrained designated :> subtype, such as: :> :> subtype Alloc_Buffer is String(1..Num_Chars); :> type Space_Ptr is access all Alloc_Buffer; :> ... :> :> X : Space_Ptr := new Alloc_Buffer; :> ... :> Pass_To_Assembler(X.all'Address); Please note that whether you have bounds or not, you do not want to pass the actual pointer to assembler or C or ... An Ada access type is a bit pattern that can be used by code from the same compiler to access the item. It does not have to be an address, though in most implementations it is. It also does not have to be the address of the actual item, and in most implementations an access to an unconstrained type is NOT the address of the item. Mr. Taft's example above is the correct way to let code from another compiler or language get the address of your object. NOT unchecked conversion from the access type to address. For some reason, I keep seeing even experienced Ada programmers use the latter (incorrect) method. (Aside: How is it that the bounds cost one Meg?) Also, be sure you know what you're doing if you try to mix malloc with new. Many Ada compilers do their own memory management. Perhaps this is because malloc is not task-safe. whatever the reason, many do not catch errors caused by the user assuming malloc and new are interchangeable. If you create something with malloc and try to destroy it with unchecked_ deallocation you can corrupt both memory managers. Likewise with new and free. -- --------------------------------------------------------------------------- W. Wesley Groleau (Wes) Office: 219-429-4923 Magnavox - Mail Stop 10-40 Home: 219-471-7206 Fort Wayne, IN 46808 elm (Unix): wwgrol@pseserv3.fw.hac.com ---------------------------------------------------------------------------