473,387 Members | 1,493 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,387 software developers and data experts.

store Array values until next time method called

Hi.
Does anyone know how can i crate an Array not managed, and it doesn't looses his contents.
My problem is:
I've a method that returns a managed array and i want to store it but i can't store it in a CollectionBase List cause the system throws me an exception stack overflow, my method is called in timer_tick.
Does anyone know how can i store that array until the next tick to compare them?
thanks
Aug 24 '07 #1
10 1699
weaknessforcats
9,208 Expert Mod 8TB
I expect you need to create the array on the heap rather than the stack. Stack memory is often limited.

Expand|Select|Wrap|Line Numbers
  1. int arr[10000];     //bad
  2. int* arr = new int[10000];    //good
  3.  
If this doesn't work, or you are already doing this, then a code snippet would be appreciated.
Aug 24 '07 #2
My problem is that i want to store the values froma a matrix that are xomputed in a method then when i repeat that method i want to have them avaiable again and subtract them from a new matrix. is like;
method(MatrizIPF)
MatrizIPF[i,j]=a;
MatrizINPF[i,j]=0;

MatrixA=MatrizIPF;
return MatrizIPF

and then call again the method
and do

MatrixA-MatrixIPF;

MatrixA=MatrixIPF;
RETURN MatrizIPF;

IS THIS MORE OR LESS
Aug 24 '07 #3
Banfa
9,065 Expert Mod 8TB
Stack memory is often limited.
I've seen you say this a few times (in various guises) now. However in my experience if stack space is limited then so is heap space (i.e. on an embedded platform) and if heap space is not particularly limited then neither is the stack space (on the Windows platform). I admit I have no knowledge of *nix platforms in this regard. This seems to stem from the fact that both are allocated from available RAM (physical and virtual in some cases) and therefore space in these segements are both ultimately dependent on the amount of RAM available on the platform and have similar limits.

While I have seen some interesting arguments on whether it is better to allocate from the stack or heap it appears to me that "because stack space is more limited than heap space" is not a particularly good one.
Aug 24 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
However in my experience if stack space is limited then so is heap space (i.e. on an embedded platform) and if heap space is not particularly limited then neither is the stack space (on the Windows platform). I admit I have no knowledge of *nix platforms in this regard.
My sole experience with this was a big Unix box running HP-UX. The stack was limited to 4096 bytes and it took a signature from a third-level manager and concurrence from the sysadmin to allow you to have more space.

The phenomenon was a run-time crash.

If you are saying that the stack will expand as necessary and that this HP-UX box (at Boeing) was an anomaly, then I will not say that again.
Aug 24 '07 #5
Banfa
9,065 Expert Mod 8TB
My sole experience with this was a big Unix box running HP-UX. The stack was limited to 4096 bytes and it took a signature from a third-level manager and concurrence from the sysadmin to allow you to have more space.

The phenomenon was a run-time crash.

If you are saying that the stack will expand as necessary and that this HP-UX box (at Boeing) was an anomaly, then I will not say that again.
Well that rather explains your statement.

I am saying the stack and heap sizes are platform dependent.

For instance on Windows the thread stacks are initially 20k bytes but will grow up to the limit of available RAM as required, I am not sure what the intiial heap size is but it too will grow as required to the limit of available RAM.

Generally on embedded platforms the stack and heap sizes are defineable. On the platform I am currently using I have a 256 byte stack and a 30k byte heap, however the stack is only used to run the background task of the RTOS, the the main working tasks then have their stacks allocated from the heap.

On another embeddd platform I have worked on the stack was been 4k bytes but the heap only 2k bytes (this was written in C and allocating space from heap was specifically prohibited), again RTOS tasks then have their own stacks too, these were allocated as static arrays of char.

Anyway stack and heap sizes are platform dependent and can be under the control of the prgrammer sometimes. Your HP-UX box is not an anomily it is just 1 way of having the stack and heap organised.
Aug 24 '07 #6
gsi
51
Hi,

store the values froma a matrix that are xomputed in a method then when i repeat that method i want to have them avaiable again
Simplest workaround is to declare the 2 dimensional array(matrix) as a seperate class member or make it static inside the method.

thanks,
gsi.
Aug 24 '07 #7
weaknessforcats
9,208 Expert Mod 8TB
Simplest workaround is to declare the 2 dimensional array(matrix) as a seperate class member or make it static inside the method.
This is the same as declaring a global variable. Only the scope is different.

There are no good reasons for using global variables.

In this case, the array should be a class private member and the class should have methods to work with the array. When an obect of the class is created, it is passed to functions using a handle. See this article in the C/C++ Articles forum.
Aug 25 '07 #8
gsi
51
Hi,

There are no good reasons for using global variables.
That's right. Sorry for the misleading info.

Thanks,
gsi.
Aug 26 '07 #9
I think i haven't explained very well my problem, i'll post my code here and i'll try to explain it.


private: System::Void timer1_Tick(System::Object * sender, System::EventArgs * e)
{

h=this->axXVideoOCX1->XGetImageHeight(imagehandle);
w=this->axXVideoOCX1->XGetImageWidth(imagehandle);
int MatrizIPF[,] = new int __gc[h,w];
int MatrizINPF[,] = new int __gc[h,w];
int MatrizVIPF[,] = new int __gc[h,w];
int MatrizVINPF[,] = new int __gc[h,w];
int teste __gc[,];
int teste2 __gc[,];

if(condition)
{

MatrixPixeisdeFogo(pixels,h,w,MatrizIPF);

}
else
{
this->textBox3->Text=" ";
}
}

int MatrixNPixeisdeFogo(unsigned char *pixels, int h, int w, int MatrizINPF __gc[,])[,]
{
if(condition)
{
MatrizINPF[i,j]=0;
}
}
else
{
MatrizINPF[i,j]=a;
}
delete crgb;
}
}
MatrizVINPFI=MatrizINPFI-MatrizINPF;
MatrizINPFI=MatrizINPF;
return something;
}

so what i would like to learn is how can i keep in MatrizINPFI the past value of MatrizINPF, is to compute the Variation of it in MatrizVINPFI.
Is it clear?
Aug 27 '07 #10
ystem.NullReferenceException: A referência de objecto não foi definida como uma instância de um objecto.
at DetectordeIncendios.Form1.MatrixPixeisdeFogo(Byte* pixels, Int32 h, Int32 w, Int32[,] MatrizIPF) in c:\documents and settings\proprietário-de-hp\ambiente de trabalho\pedro\projecto\detector de incendios prototipoii\form1.h:line 452
at DetectordeIncendios.Form1.timer1_Tick(Object sender, EventArgs e) in c:\documents and settings\proprietário-de-hp\ambiente de trabalho\pedro\projecto\detector de incendios prototipoii\form1.h:line 332
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.Callback(IntPtr hWnd, Int32 msg, IntPtr idEvent, IntPtr dwTime)
Aug 27 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Christopher Brandsdal | last post by:
Hi! I have a delicatg problem.... I have made a registration form for adding my friends information in a database. The problem is that I want to connect the persons with companies in the same...
11
by: Colin Steadman | last post by:
Hope this makes sense! I'm building an ASP page which allows uses to add items to an invoice via a form, ie: Item No Part No Order No Quanity Units Price VAT ------- ...
2
by: Nick | last post by:
Loop to create an array from a dynamic form. I'm having trouble with an application, and I'll try to explain it as clearly as possible: 1. I have a form with two fields, say Apples and...
7
by: Christopher Jeris | last post by:
I am relatively new to JavaScript, though not to programming, and I'm having trouble finding the idiomatic JS solution to the following problem. I have a table with (say) fields f1, f2, f3. I...
14
by: Randell D. | last post by:
Folks, Here's my problem: I am createing an array in a file using the reslut of some PHP and MySQL processing. An example of my array would be examlpe="example one"; examlpe="example...
6
by: Herrcho | last post by:
in K&R Chapter 6.3 it mentions two methods to calculate NKEYS. and points out the first one which is to terminate the list of initializers with a null pointer, then loop along keytab until the...
19
by: Tom Jastrzebski | last post by:
Hello, I was just testing VB.Net on Framework.Net 2.0 performance when I run into the this problem. This trivial code attached below executed hundreds, if not thousand times faster in VB 6.0...
9
by: garyusenet | last post by:
I'm a bit confused about the differences of these two commands (what is the right word for commands here?) when used to enumerate the contents of an array. The below example uses both foreach...
14
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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,...

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.