Re: [gtk-list] glib memory management?



On Tue, 20 Apr 1999 20:57:40 +0200, gtk-list@redhat.com (Drazen Kacar) wrote:
> Does glib's memory management provides a way to manage a bunch of pages
> which are not on heap? That is, I'd like to get some shared memory (or
> mmap() anonymous segment) and tell glib "here is the nice 64K of memory
> that needs your management". Then I would get some descriptor for it
> which I would use in subsequent calls to xx_malloc(), xx_realloc() and
> xx_free() functions. There should be a way to force garbage collection
> when it runs out of space and a way to destroy this segment.

I don't know about a way to manage a bunch of assigned memory, but I like
the idea of having a memory manager for shared memory. There are however a
couple of problems to solve:

- Locking in the memory manager: the idea of a shared memory segment is
  that it is shared between processes (sic). If one of them allocates a
  piece of memory in the segment, others shouldn't be able to do the same,
  so you need some kind of locking, like SYSV IPC semaphore sets.
- If the heap in the shared memory segment is corrupted and the memory
  manager crashes, the lock is not released and all other processes hang,
  so you must have some way to timeout and solve the problems.
- You can't guarantee that each process has the shared memory segment
  mapped at the same address in its address space. The data structures in
  the memory manager should work with relative addresses to avoid problems.
- Related with the previous problem is that you have to be careful with
  what you allocated in shared memory. Just an array of integers is no
  problem, but the addresses in an array of pointers to integers are valid
  for only one process.

I've encountered the same problems with sharing an image (image header
plus a bunch of image data) in a multi-agent system. I solved the locking
problem by mapping the shared memory segment read-only, except for the
agent who allocated it. After that, I had to do some pointer arithmetic to
construct a new image header for the image data in the shared memory
segment. My experience is that shared memory works good for well-defined
data types, but not for arbitrary types.


Erik

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2785859  Fax: +31-15-2781843  Email J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]