Skip to content

[BZ-1991] Unable to access ACE_Based_Pointer_Repository Singleton in a DLL #1991

@jwillemsen

Description

@jwillemsen
Field Value
Bugzilla ID 1991
Reporter Steve Williams
Assigned to Steve Williams
Product ACE
Component ACE Core
Version 5.4
Platform / OS x86 / Windows 2000
Priority P3
Severity normal
Status RESOLVED
Resolution FIXED
Created 2004-11-26 14:34:00 -0600
Depends on #2260
Blocks #2216, #2218

Originally posted by Steve Williams on 2004-11-26 14:34:01 -0600


I am developing a DLL that supports shared memory mapped containers, the
containers are allowed to grow in size. This means that the memory pool base
addresses can be changed during the life of the application, so after each
reallocation operation ACE_Based_Pointer_Basic pointers to objects in that
pool must be recalculated, i.e.

  T *tmp;
  char* datap = (char*)this->array_.addr();
  void *obase_addr = 0;
  void *nbase_addr = 0;

  // Find the base address associated with the <array_> pointer.
  // Note that it's ok for <find> to return 0, which simply
  // indicates that the address is not in memory-mapped virtual
  // address space.
  ACE_BASED_POINTER_REPOSITORY::instance ()->find (datap,
                                                   obase_addr);

  ACE_ALLOCATOR_RETURN (tmp,
                        (T *) this->allocator_->malloc (new_size * sizeof 

(T)),
-1);
ACE_BASED_POINTER_REPOSITORY::instance ()->find (tmp,
nbase_addr);
if(obase_addr != nbase_addr)
{
// Reallocation caused memory segment to move
// in the virtual address space. The array_ pointer
// is no longer valid, recalculate so that the
// data array can be accessed
this->array_ = (T*)((datap - (char*)obase_addr) + (char*)
nbase_addr);
}

The problem is that the container DLL allocates a new instance of the
Singleton ACE_Based_Pointer_Repository and the code above fails.

I fixed the problem by adding the following declaration to
ace/Based_Pointer_Repository.h:

ACE_SINGLETON_DECLARE(ACE_Singleton, ACE_Based_Pointer_Repository,
ACE_SYNCH_RW_MUTEX)

Now a single process wide instance of the ACE_Based_Pointer_Repository is used.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions