473,405 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Global Arrays

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.
Nov 30 '07 #1
5 1908
Chandra wrote:
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?
--
Ian Collins.
Nov 30 '07 #2
On Nov 30, 9:49 am, Chandra <forquer...@gmail.comwrote:
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?
Nov 30 '07 #3
On Nov 30, 7:49 am, Chandra <forquer...@gmail.comwrote:
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;
Nov 30 '07 #4
On Nov 30, 10:11 am, mr.xiaofan...@gmail.com wrote:
On Nov 30, 7:49 am, Chandra <forquer...@gmail.comwrote:
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;
And you get your array globally everywhere by referring to
MyArrays::Singleton() . Enjoy!
Nov 30 '07 #5
On Nov 30, 12:11 pm, mr.xiaofan...@gmail.com wrote:
On Nov 30, 7:49 am, Chandra <forquer...@gmail.comwrote:
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;
This is not a singleton!
Nov 30 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Larry L | last post by:
I have a Module that declares several arrays as public, some string, some integers. I then have 2 forms. Form A is the main form, that loads on start-up, and has a command button to open Form B. On...
1
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. In fact there...
2
by: Patient Guy | last post by:
I have a library of functions representing a filesystem interface (essentially a file selection interface, to be used in opening/reading/writing/closing files). Heavily scripted HTML document...
33
by: MLH | last post by:
I've read some posts indicating that having tons of GV's in an Access app is a bad idea. Personally, I love GVs and I use them (possibly abuse them) all the time for everything imaginable - have...
4
by: Sheldon | last post by:
Hi, I have a series of classes that are all within the same file. Each is called at different times by the main script. Now I have discovered that I need several variables returned to the main...
19
by: Jim West | last post by:
The execution speed of the following code is dramatically faster if I declare some arrays globally rather than locally. That is FOO a, b, c; void bar() { ... } runs much faster (up to...
5
by: Rahul B | last post by:
Hi, I have very little knowledge about creating Procedures/functions in DB2. When i tried to create the test function like CREATE FUNCTION GET_TEST (P_TEST_ID INTEGER, P_SEL_OR_SORT...
3
by: Jeff | last post by:
Quick questions I can't find answers to: Is there a shortcut to do this: if(! $some_var){$some_var = 'some_other_value'} I'm used to this: $some_var ||= 'some_other_var'; PHP manual doesn't...
18
by: Bruce | last post by:
When I do this: <input id="someName" type="text"> <script type="text/javascript"> alert(someName.nodeName); </script> Both IE6 and Firefox alert("INPUT"). Why isn't "someName" undefined?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.