|
Hi,
IIRC stack space is limited to 1MB, so you can't create a stack-based array holding 1M elements. You could dynamically allocate it though, using malloc() or new.
|
|
|
|
|
I'm going by memory, too, but I think the default stack is 1 Meg but you can set it to be a different size as part of the build. I've never personally done it though.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Tim Craig wrote: but you can set it to be a different size as part of the build.
yeah, that is very plausible, however I never have done so for a Windows app.
|
|
|
|
|
Tim Craig wrote: but you can set it to be a different size as part of the build.
yeah, that is very plausible; it is common practice for embedded systems, however I never have done so for a Windows app.
|
|
|
|
|
You remember well [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I remember a poem in Mad Magazine in the late 50's that went "I remember, I remember...", but I can't remember what they remembered.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
You are lucky. On the other hand:
"I don't remember, I don't recall
I got no memory of anything at all"
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Try with malloc, that can used to represent multidimensional array.
int **nArray;
int nRows = 10000;
int nColumn = 100;
nArray = (int**)malloc(nRows * sizeof(int *));
ZeroMemory( nArray, 0 );
if( 0 == nArray )
{
return 0;
}
for(int i = 0; i < nRows; i++)
{
nArray[i] = (int*)malloc( nColumn * sizeof(int));
if( 0 == nArray[i] )
{
return 0;
}
}
Величие не Бога может быть недооценена.
|
|
|
|
|
so i tried this but keep getting errors on _variant_t *p line:
****************************************************
initialize array
vector<_variant_t> d(10000);
//_variant_t** 2d = new _(variant_t*)[10000];
for(long k = 0; k < d.size(); ++k)
{
d[k] = new _variant_t();
***********************************************************
delete array
for(k = 0; k < d.size(); ++k)
{
_variant_t* p = d[k]; (error = cannot convert from 'class _variant_t' to 'class _variant_t *')
delete [] p;
}
|
|
|
|
|
hi,
use vector<_variant_t*> d(10000);
instead of
vector<_variant_t> d(10000);
|
|
|
|
|
Thanks it worked but even after compiling the code, i still get stack overflow:
this is how am declaring my array:
static const int N = 9990;<br />
static const int N2 = 96;<br />
<br />
<br />
vector<_variant_t*> d(N);<br />
<br />
<br />
for(long k = 0; k < d.size(); ++k)<br />
{<br />
d[k] = new _variant_t();<br />
}<br />
<br />
<br />
_variant_t raw_data[N][N2];<br />
<br />
_variant_t filter_results[N2];<br />
<br />
_variant_t results2[N][N2]<br />
<br />
_variant_t Filtered_Average[N];
|
|
|
|
|
you are trying to create a multidimenional array on stack. normally stack has a limitation of 2MB but heap can go upto around 100 MB.
create all the variables in heap and importantly delete it after using. this is a classic multi dimension c++ mem allocation.
sample :
_variant_t **raw_data[N];
for(int nOut = 0;nOut < N;nOut++)
{
raw_data[nOut] = new _variant_t*[N2];
for(int nIn = 0;nIn < N2;nIn++)
{
raw_data[nOut][nIn]= new _variant_t(nIn);// sample initialization
}
}
// delete this is important
for(int nOut = 0;nOut < N;nOut++)
{
for(int nIn = 0;nIn < N2;nIn++)
{
delete raw_data[nOut][nIn];
}
delete raw_data[nOut] ;
}
|
|
|
|
|
Thanks to everyone who tried to help out.
Sorry, my bad, this was a red herring.
I found out that I was overrunning an array because the spec of other parts of the software had changed without my knowledge.
I've increased the memory allocation accordingly, and it is fine now.
==================================================================
I'm having trouble with destructors and delete .
I have some embedded structure so in order to delete one of my objects, I have to call lots of desctructors in a hierarchical way:
void CMyBigClass::StartKilling()
{
if(NULL != m_pSubObject1)
{
delete m_pSubObject1;
m_pSubObject1 = NULL;
}
}
...
CSubObject1::~CSubObject1()
{
if(NULL != m_pSubObject2)
{
delete m_pSubObject2;
m_pSubObject2 = NULL;
}
}
...
CSubObject2::~CSubObject2()
{
if(NULL != m_pSubObject3)
{
delete m_pSubObject3;
m_pSubObject3 = NULL;
}
}
Normally, if I set a break point on the
delete m_pSubObject1;
line and step in (F11), I land in the first line of the desctructor fo CSubObject1.
However, I jump straight to
delete m_pSubObject3;
where I get a heap error.
I looked into as much as I could, and the debugger isn't lying. The memory it is trying to delete is different from what I told it to delete. Something is trampling over the memory, but I don't know what. I don't know how to find out either.
I've undone all the changes since the last time it was working, but still the same problem.
Please, someone, tell me how to find out what's gone wrong!!
Almost, but not quite, entirely unlike... me...
modified on Tuesday, April 6, 2010 3:16 AM
|
|
|
|
|
Surely some sort of heap corruption. Please show the code of allocation.
And if you can just check with Windbg.
Величие не Бога может быть недооценена.
|
|
|
|
|
PaulowniaK wrote: However, I jump straight to
0. Can you step to delete m_pSubObject3 too (or jump only ?) ?
1. Please set a breakpoint at the first line of CSubObject3::~CSubObject3() -
maybe, the code will be called earlier (than from CSubObject2::~CSubObject2() )...
virtual void BeHappy() = 0;
modified on Tuesday, April 6, 2010 2:47 AM
|
|
|
|
|
Just an aside comment on your code. You do know that you can safely delete a NULL pointer? The check for NULL is done internally to delete so you don't have to check yourself.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
I understand the concept of an instance, but I however don't see the effects of including it over and over.
Any good uses? 
|
|
|
|
|
Could you include an example, for instance.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
|
|
|
|
|
Don't know what you're asking, but an instance/module handle is important when dealing with pulling resources from a specific executable (exe or dll) in a process.
|
|
|
|
|
What benefits do I get from including hInstance every time I pass it in a CreateWindow?
I can simply put NULL and still successfully Create the Window. 
|
|
|
|
|
|
I use an example to explain:
The CListCtrl contains :
* 2 columns
room name and value, different rooms may have same value.
* 100 rows
each row represents a room.
Item data are assigned with room ID (int), which are from 1 to 100 uniquely.
When user clicks CListCtrl header of name or value, items are sorted ascendantly or decendently with name or value respectively.
Above are easy, now I need extra sorting:
The room with ID of 10 exactly follows room 9, 20 follows 19, and so on to 100 follows 99.
In other words, (9,10), (19,20), ..., (99,100) are in "team".
The extra sorting is not affected by name and value sorting.
Any ideas or suggestions?
Thanks.
|
|
|
|
|
includeh10 wrote: ...10 exactly follows room 9, 20 follows 19, and so on to 100 follows 99.
Last time I checked, that's how numbers are ordered anyway. Are you seeing something different?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
actually i want the c code for the following algo......
for(i=Len-1;i>=0;i--) if (Elem[i] is a logical expression) PC = PC U{Elem[i]}; else /* Elem[i] is an assignment */ substitute(PC,Elem[i]);
Given a path P, let PCp denote the set of path conditions. P is a sequence of logical expressions and assignment statements. We use Elem P [i] to denote the i'th element of the sequence, and use Len P to denote P's length (i.e., the number of logical expressions and assignments in P). The subscriptP may be omitted when no confusion occurs. Then PC can be obtained in the following way: for(i=Len-1;i>=0;i--) if (Elem[i] is a logical expression) PC = PC U{Elem[i]}; else /* Elem[i] is an assignment */ substitute(PC,Elem[i]);
The procedure substitute() changes the PC using an assignment. Firstly we consider the trivial case when the left-hand side of the assignment is a simple variable x. In this case, every occurrence of x in PC is replaced by the right-hand side of the assignment.
Example 1. Suppose we need input data such that the procedure qr executes along Path 2. We may specify the path as follows: int m, n, q, r; { r = m; q = 0;
1. r >= n;
r = r-n; q = q+1;
1. r < n;
}
Here we use the symbol `@' to distinguish logical expressions from assignment statements. Our tool PAT generates the following constraints: m-n >= 0; m-2n < 0;
|
|
|
|
|