Global Arrays

C

Chandra

Hi,

I have three files in which i am using 10 arrays each of size( say
about 600 i.e A1[600],A2[600] ......A10[600]). I am having some memory
issues so i want to make use of the memory in a appropraite way. These
array are declared as global in one of the files and are being used in
the other files. But my concern i want to declare them in one of the
file as local to that file and make them available in other files too.
The reason behind this is the array declared global are available to
the other files which don't require the access to these arrays.

So on a whole my query is : How can we use the variables which are
declared local to one class.

Probably Inheritance is one of the ways to acheive this. But i don't
require this. Is there any other way to do this. Any suggestion will
be helpful to me.

Thnx in advance..

Chandra.
 
I

Ian Collins

Chandra said:
Hi,

I have three files in which i am using 10 arrays each of size( say
about 600 i.e A1[600],A2[600] ......A10[600]). I am having some memory
issues so i want to make use of the memory in a appropraite way. These
array are declared as global in one of the files and are being used in
the other files. But my concern i want to declare them in one of the
file as local to that file and make them available in other files too.

That's a contradiction.
The reason behind this is the array declared global are available to
the other files which don't require the access to these arrays.

So on a whole my query is : How can we use the variables which are
declared local to one class.
Make them static members?
 
A

asterisc

Hi,

I have three files in which i am using 10 arrays each of size( say
about 600 i.e A1[600],A2[600] ......A10[600]). I am having some memory
issues so i want to make use of the memory in a appropraite way. These
array are declared as global in one of the files and are being used in
the other files. But my concern i want to declare them in one of the
file as local to that file and make them available in other files too.
The reason behind this is the array declared global are available to
the other files which don't require the access to these arrays.

Thnx in advance..

Maybe using Singleton pattern?
 
M

mr.xiaofan.li

Hi,

I have three files in which i am using 10 arrays each of size( say
about 600 i.e A1[600],A2[600] ......A10[600]). I am having some memory
issues so i want to make use of the memory in a appropraite way. These
array are declared as global in one of the files and are being used in
the other files. But my concern i want to declare them in one of the
file as local to that file and make them available in other files too.
The reason behind this is the array declared global are available to
the other files which don't require the access to these arrays.

So on a whole my query is : How can we use the variables which are
declared local to one class.

Probably Inheritance is one of the ways to acheive this. But i don't
require this. Is there any other way to do this. Any suggestion will
be helpful to me.

Thnx in advance..

Chandra.

class MyArrays
{
public:

MyArrays(...)
{
// array initialisation ...
}

static MyArrays& Singleton()
{
if (!m_pSingleton) m_pSingleton = new MyArrays(...);
return *m_pSingleton;
}

private:

int m_array [NUM];
static MyArrays* m_pSingleton;
}

// don't forget to init the static variable in your source (cpp) file
MyArrays* MyArrays::m_pSinglton = NULL;
 
M

mr.xiaofan.li

I have three files in which i am using 10 arrays each of size( say
about 600 i.e A1[600],A2[600] ......A10[600]). I am having some memory
issues so i want to make use of the memory in a appropraite way. These
array are declared as global in one of the files and are being used in
the other files. But my concern i want to declare them in one of the
file as local to that file and make them available in other files too.
The reason behind this is the array declared global are available to
the other files which don't require the access to these arrays.
So on a whole my query is : How can we use the variables which are
declared local to one class.
Probably Inheritance is one of the ways to acheive this. But i don't
require this. Is there any other way to do this. Any suggestion will
be helpful to me.
Thnx in advance..

class MyArrays
{
public:

MyArrays(...)
{
// array initialisation ...
}

static MyArrays& Singleton()
{
if (!m_pSingleton) m_pSingleton = new MyArrays(...);
return *m_pSingleton;
}

private:

int m_array [NUM];
static MyArrays* m_pSingleton;

}

// don't forget to init the static variable in your source (cpp) file
MyArrays* MyArrays::m_pSinglton = NULL;

And you get your array globally everywhere by referring to
MyArrays::Singleton() . Enjoy!
 
A

asterisc

I have three files in which i am using 10 arrays each of size( say
about 600 i.e A1[600],A2[600] ......A10[600]). I am having some memory
issues so i want to make use of the memory in a appropraite way. These
array are declared as global in one of the files and are being used in
the other files. But my concern i want to declare them in one of the
file as local to that file and make them available in other files too.
The reason behind this is the array declared global are available to
the other files which don't require the access to these arrays.
So on a whole my query is : How can we use the variables which are
declared local to one class.
Probably Inheritance is one of the ways to acheive this. But i don't
require this. Is there any other way to do this. Any suggestion will
be helpful to me.
Thnx in advance..

class MyArrays
{
public:

MyArrays(...)
{
// array initialisation ...
}

static MyArrays& Singleton()
{
if (!m_pSingleton) m_pSingleton = new MyArrays(...);
return *m_pSingleton;
}

private:

int m_array [NUM];
static MyArrays* m_pSingleton;

}

// don't forget to init the static variable in your source (cpp) file
MyArrays* MyArrays::m_pSinglton = NULL;

This is not a singleton!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,186
Messages
2,570,997
Members
47,586
Latest member
Gilda57E93

Latest Threads

Top