|
On Mon, 8 Apr 2002, John Taylor wrote: > Group, > > I'm building a service program (in RPG) with the intent of simplying the use > of dynamic heap storage. One of the first things I've come across is the > need to determine the amount of storage already allocated to a basing > pointer. Since there is nothing in RPG, or the C runtime, that provides this > information, I'm hoping that MI may provide a solution. > > I would appreciate it someone could point me in the right direction. RTFM > will work, but which manual? And is there a specific instruction that I > should look for? I don't know of a way to ask the system how much memory is allocated (I imagine you could do it in MI, but I'm still learning MI) However, if you're doing all the memory management yourself in a service program, you could consider just allocating some extra memory for a variable that contains the allocated size: I mean, something like this: P my_alloc B D my_alloc PI * D space 10I 0 value D p_memory S * D curr_size S 10I 0 based(p_memory) c eval space = space + 4 c alloc(e) space p_memory c if %error c return *NULL c endif c eval curr_size = space - 4 c eval p_data = p_memory + 4 c return p_data P E So, p_data would be what the caller would actually use... When the caller called my_dealloc, you'd take the pointer that got passed in, subtract 4 from it, and that would be the area to dealloc. If the caller called my_realloc, you'd do the same thing, subtract 4, get the size from the integer stored there, and use that size when realloc-ing the memory... If you need to mix & match with callers that use the RPG alloc & dealloc op-codes, though, you're going to have problems no matter what you do :)
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.