Swaminathan N. (swami++at++evl.uic.edu)
Tue, 25 Nov 1997 14:15:43 -0600 (CST)
> I have a set of C++ templates that use the STL for managing information
> for display. I'm wondering about how the data is managed between
> processes since the data must be seen by at least the APP and the DRAW
> processes. Do I need a special new and delete operator that allocates
> from the shared arena?
Yes.
> ... Any thing to watch out for?
You may also need to supply an allocator that allocates from the shared
arena. Here is some untested code that may do the trick
// MwIrixMemory.h
#include <Performer/pr/pfMemory.h>
#include <new.h>
class shmalloc {
private:
static void (* oom_handler)();
static void *oom_malloc(size_t);
static void *oom_realloc(void *, size_t);
public:
static void * allocate(size_t n) {
void *result = pfMemory::malloc(n, pfGetSharedArena());
if (0 == result) result = oom_malloc(n);
return result;
}
static void deallocate(void *p, size_t /* n */) {
pfMemory::free(p);
}
static void * reallocate(void *p, size_t /* old_sz */, size_t new_sz) {
void * result = pfMemory::realloc(p, new_sz);
if (0 == result) result = oom_realloc(p, new_sz);
return result;
}
static void (* set_malloc_handler(void (*f)()))() {
void (* old)() = oom_handler;
oom_handler = f;
return(old);
}
};
#ifdef INCLUDE_TEMPLATE_BODY
#include "MwIrixMemory.cxx"
#endif
// MwIrixMemory.cxx
void (* shmalloc::oom_handler)() = 0;
void * shmalloc::oom_malloc(size_t n) {
void (* my_malloc_handler)();
void *result;
for (;;) {
my_malloc_handler = oom_handler;
if (0 == my_malloc_handler) { __THROW_BAD_ALLOC; }
(*my_malloc_handler)();
result = pfMemory::malloc(n, pfGetSharedArena());
if (result) return(result);
}
}
void * shmalloc::oom_realloc(void *p, size_t n) {
void (* my_malloc_handler)();
void *result;
for (;;) {
my_malloc_handler = oom_handler;
if (0 == my_malloc_handler) { __THROW_BAD_ALLOC; }
(*my_malloc_handler)();
result = pfMemory::realloc(p, n);
if (result) return(result);
}
}
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
v Swaminathan Narayanan ^
v swami++at++multigen.com ^
v Office: (408) 261-4100 ^
v Home: (408) 248-8563 ^
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
=======================================================================
List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/
Submissions: info-performer++at++sgi.com
Admin. requests: info-performer-request++at++sgi.com
This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:56:15 PDT