how to allocate a pointer with changing memory size inside a program 
Author Message
 how to allocate a pointer with changing memory size inside a program

hi,
  I have a CMyDialog and I defined a pointer Test_Pointer to UCHAR as a
member variable, and in the dialogs constructor I allocate the pointer with
a array of type UCHAR with a initial size, after that I stored the initial
size in  Test_Pointer[0] . And in one of the member function I want to get
the Test_Pointer[0] out for use, but I couldnt get it any more just like
the Test_Pointer never exist. Because I want to change the size of the array
in the subsequent  functions and always keep the last results  in this
array, so how could I define the array like a global variable? And  should I
release the memory of  last size before I allocate the pointer with a new
size ? Thanks a lot.
xingfu


Tue, 21 Jun 2005 15:03:00 GMT  
 how to allocate a pointer with changing memory size inside a program
Whatever Test_Pointer[0] points to must persist after the constructor.  This
implies either a global variable or another member variable.  Using either
of these, however, squelches the need to store the size in Test_Pointer[0].


Quote:
> hi,
>   I have a CMyDialog and I defined a pointer Test_Pointer to UCHAR as a
> member variable, and in the dialogs constructor I allocate the pointer
with
> a array of type UCHAR with a initial size, after that I stored the initial
> size in  Test_Pointer[0] . And in one of the member function I want to get
> the Test_Pointer[0] out for use, but I couldnt get it any more just like
> the Test_Pointer never exist. Because I want to change the size of the
array
> in the subsequent  functions and always keep the last results  in this
> array, so how could I define the array like a global variable? And  should
I
> release the memory of  last size before I allocate the pointer with a new
> size ? Thanks a lot.
> xingfu



Tue, 21 Jun 2005 15:38:19 GMT  
 how to allocate a pointer with changing memory size inside a program
hi,David
 thanks a lot. But I am sorry, I dont understand  what you mean very well,
and the problem is not wheather I store the size in Test_Pointer[0] or not,
but is that I couldnt find the data which were stored in the array pointed
by Test_Pointer after  constructor.Could you give me more concrete advice?
thanks in advance.
xingfu



Quote:
> Whatever Test_Pointer[0] points to must persist after the constructor.
This
> implies either a global variable or another member variable.  Using either
> of these, however, squelches the need to store the size in
Test_Pointer[0].



> > hi,
> >   I have a CMyDialog and I defined a pointer Test_Pointer to UCHAR as a
> > member variable, and in the dialogs constructor I allocate the pointer
> with
> > a array of type UCHAR with a initial size, after that I stored the
initial
> > size in  Test_Pointer[0] . And in one of the member function I want to
get
> > the Test_Pointer[0] out for use, but I couldnt get it any more just
like
> > the Test_Pointer never exist. Because I want to change the size of the
> array
> > in the subsequent  functions and always keep the last results  in this
> > array, so how could I define the array like a global variable? And
should
> I
> > release the memory of  last size before I allocate the pointer with a
new
> > size ? Thanks a lot.
> > xingfu



Tue, 21 Jun 2005 15:53:34 GMT  
 how to allocate a pointer with changing memory size inside a program
What do you mean by "couldn't find?"  I may be way off base here but let's
assume you have something like the following:

class CMyClass
{
public:
    CMyClass( void );
    ~CMyClass( void );

    SomeMethod( void );

private:
    UCHAR *TestPointer;

Quote:
};

CMyClass::CMyClass( void )
{
    TestPointer = new UCHAR[3];
    TestPointer[0] = 'A';
    TestPointer[1] = 'B';
    TestPointer[2] = 'C';

Quote:
}

CMyClass::~CMyClass( void )
{
    delete [] TestPointer;
    TestPointer = NULL;

Quote:
}

CMyClass::SomeMethod( void )
{
    if (TestPointer != NULL)
    {
        TRACE("TestPointer[0] = %u\n", TestPointer[0]);
        TRACE("TestPointer[1] = %u\n", TestPointer[1]);
        TRACE("TestPointer[2] = %u\n", TestPointer[2]);
    }

Quote:
}

Does this help?


Quote:
> hi,David
>  thanks a lot. But I am sorry, I dont understand  what you mean very
well,
> and the problem is not wheather I store the size in Test_Pointer[0] or
not,
> but is that I couldnt find the data which were stored in the array
pointed
> by Test_Pointer after  constructor.Could you give me more concrete advice?
> thanks in advance.
> xingfu



Tue, 21 Jun 2005 20:04:45 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. size of allocated memory only given pointer

2. Questions about memory size and memory allocate.

3. Dynamic allocate memory size in memory mapping

4. Allocating memory inside a function

5. Freeing memory allocated inside a function

6. Help with Re-Allocating Memory inside a structure

7. getting the size of allocated memory via Marshal.SizeOf

8. size of memory allocated

9. Problem De-allocating Memory in variable sized arrays

10. Help getting size of binary file for allocating pointer array

11. Reg.allocating memory for double char pointer(char ** buf)

12. determining the memory allocated to pointer.

 

 
Powered by phpBB® Forum Software