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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,869db548a0882a13,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Counting Elements? Date: 02 Dec 2005 13:44:56 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1133549096 20601 192.74.137.71 (2 Dec 2005 18:44:56 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 2 Dec 2005 18:44:56 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:6722 Date: 2005-12-02T13:44:56-05:00 List-Id: Freejack writes: > I've been fiddling with Storage Pools. I can get the Allocate procedure to > allocate from an mmap() region quite easily. I can access it, play with > it, and do all the naughty stuff you're not supposed to be doing with Ada. ;-) Ada doesn't _prevent_ low-level stuff. It just allows you to isolate it so the "naughty" stuff doesn't pollute the higher-level stuff. Ada is actually a better language than C for programming close to the metal (IMHO). > However I'm a little confused about a couple > things. Storage_Count depends on Storage_Offset, which depends on > Storage_Element, which depends on Storage_Unit(On GNAT Linux 32bit, > Storage_Unit is 8). > So, if I understand it correctly a 32bit Integer would be measured this > way ... > > type Integer32 is array (Storage_Offset range 1..4) of > aliased Storage_Element; Yes. The size passed to Allocate is in "storage elements", which most people, on most machines, call "bytes". Except in the embedded world, storage elements are usually 8 bits in size. Storage_Unit is just the size (in bits) of a Storage_Element; that is: Storage_Element'Size = Storage_Unit Ada measures most sizes in bits. The size passed to Allocate is an exception. Note that the compiler automatically calculates this size. So if you say "new Integer" it will pass 4 to Allocate, which should allocate 4 storage elements, and return the address. > I gotta make sure I understand this correctly so I can pass the right > Sizes to my Region allocators before calling mmap(). > > Also, while I can call munmap() directly from anywhere, my overidden > Deallocate procedure doesn't seem to be using it.(At least from what I see > using strace and my debugger. Rather than dumping the memory back to the > system at the end of a block(declare, subprogram, etc...)like I assumed > it's suppose to, it looks like it just keeps reusing the same memory over > and over again. I assumed that Deallocate is called whenever the access > type to the pool goes out of scope. Is this true? Or do I have to pass the > access pointer to a Finalize procedure? My goal is to basically dump the > entire allocated area immediately back to the Host System as soon as the > access goes out of scope. I think you're confused. Allocate is called for each "new". Deallocate is called for each call to an instance of Unchecked_Deallocation. I think what you want is something like this: Initialize of your pool type should call mmap. Finalize of your pool type should call munmap. Allocate should allocate small pieces out of the mmap'ed area. Deallocate should free those small pieces, allowing them to be reused by future allocates. Finalize, not Deallocate, is called when one of your pool objects goes out of scope. (Storage pools are derived from Limited_Controlled, so they have the normal Initialize/Finalize features of all controlled types.) Maybe I'm confused about what you're trying to accomplish. If so, you should post some example code that uses your storage pool, and explain what you want it to do. To debug, I suggest putting print-out statements in those four routines, rather than messing around with strace or the debugger. > Except for all that, everything else is working smoothly. > > Currently I'm working on a downward growing Parameter stack Region(for > starters). Think Forth style stacks. Anyone have a use for something like > that? I think you should post a package spec with comments explaining what it does in more detail. - Bob