scope rules

Hi forum,

I have a class only to hold the references of the memories allocated inside another class as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
   class osgOpenCLBufferObject : public osgCompute::MemoryObject
   {
   public:
      void* _m_clHostPtr;                // pointer to the host
      cl_mem* _m_clDevPtr;               // pointer to the device generic linear memory
      cl_mem* _m_clDevArrayPtr;          // pointer to the device array for the 1D/2D/3D texture

      cl_mem* _m_clPinnedDevPtr;         // pointer to the pinned device generic memory
      cl_mem* _m_clPinnedDevArrayPtr;    // pointer to the pinned device array for the 1D/2D/3D texture

      unsigned int _m_clModifyCount;
      
      //declare the OpenCL events here if necessary
      
      osgOpenCLBufferObject();
      virtual ~osgOpenCLBufferObject();
      
   private:
      
      //not allowed to call copy-constructor or copy-operator
      osgOpenCLBufferObject(const osgOpenCLBufferObject&) {}
      osgOpenCLBufferObject& operator=(const osgOpenCLBufferObject&) { return *this;}
   };


The following class is actually allocating the memory in one of the functions:

1
2
3
4
5
6
7
8
9
10
11
12
13

bool Buffer::alloc()
{
.......................
.......................
cl_mem deviceMem = clCreateBuffer(...);


//_memory is initiated in the class's constructor
_memory._m_clDevPtr = &deviceMem;

}


At the end of the function i believe the scope of the deviceMem ends. But
_memory._m_clDevPtr still points to the memory allocated by the function.
Will the pointer be pointing to something valid or not?

I checked it and it says the _memory._m_clDevPtr != NULL.

But according to the program output it is not the valid memory.

Any thoughts on this?

Regards
Sajjad
The pointer is invalid
An invalid pointer is not automagically set to NULL.
Topic archived. No new replies allowed.