|
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;
|
|
|
|
|
|
hi,
can i set my application's code page programatically?
|
|
|
|
|
The Code-page (what code-points are supported and translated into what glyphs) is a system attribute.
It can be changed, but relates to the system, not the single application.
What an application can do is use one of the code-pages installed on a system when reading/writing ANSI files.
But the code-page used with the ANSI GUI functions is the one specified by the GUI user respect to the system.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
Suppose I have a VC++ project contains no of(say e.g 5) Source files(.cpp files),it will generate 5 .obj files(obj files corresponding to my .cpp's files not all kernel and OS layers including .obj files)
e.g my project includes xyz_1.cpp,xyz_2.cpp,xyz_3.cpp,xyz_4.cpp,it will corresponds 4 respective .objs.
By programtaically HOW CAN I TAKE AND GET THE NAMES OF THESE 4 .OBJ files at runtime(On run time I need to check how many obj files & names of those objs).
REMEMBER I DON'T NEED ALL KERNEL AND OS LAYER .OBJS I ONLY NEED OBJS OF MY .CPPs.
Regards
Usman
-- Modified Monday, April 5, 2010 8:19 AM
|
|
|
|
|
Well, presumably the obj files will take the same name as the cpp files - differing only in the extension.
Also, being lowly .obj files, they won't necessarily exist in the installed version of the program (nor am I able see a reason at this time to choose to include them)
Sooo, I'd just use the _FILE_ macro and do a string replace on the extension, changing it from .cpp to .obj
Here's about the cheapest, nastiest example I can think of right now. I'll leave it to you to figure out how to change the folder names...
#include <iostream>
using namespace std;
int main()
{
char *buffer;
char *insertPos;
cout << "Source File name: " << __FILE__ << endl;
buffer = new char[strlen(__FILE__)+1];
strcpy(buffer, __FILE__);
insertPos = strstr(buffer, ".cpp");
strcpy(insertPos, ".obj");
cout << "OBJ File name: " << buffer << endl;
delete buffer;
return 0;
}
|
|
|
|
|
its just a convertor to .obj file from .cpp, while taking current cpp file.
My requirement is some how I can check how many no Of OBJ files(only .obj files corresponds to .cpp files which are included in project not every kernel or OS related file)
e.g I have two files (abc.cpp and xyz.cpp) these corresponds to (abc.obj and xyz.obj) only these 2 obj's i need to get at runtime that's it.
In other words at RUNTIME I can give the exe file name , and it should give me all .obj files OR source files which are participating in that project. that's it.
AGAIN NO ANY .OBJ FILE NEEDED THOSE ARE OF KERNEL OR OS related file or IO related which I did'nt defined in my project EXPLICITELY.
|
|
|
|
|
|
Just a suggestion. If the .OBJ files contains debug information, there maybe some API's to use in order to obtain what .CPP file the object came from. A runtime debugger will need to know this, but I have no idea of how it is accomplished.
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]
|
|
|
|
|
hi,
i have localized my application and converted it to unicode.when i set code page in control panel to english everything shows in japanese except msflexgrid headers.can any one tell me how to resolve the issue?
|
|
|
|
|
Hi,
Can anyone give an example of CListCtrl::SortGroups.I want to sort the groups alphabetically.
Thanks.
|
|
|
|
|
Check the code associated with this article.
"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
|
|
|
|
|
Hi,
I have a small programm which listen a socket in a new thread. but I want to restart the porgramm after the first message.
Start the thread in main.cpp
<code>hThread = CreateThread(
NULL,
0,
ThreadFunc,
&dwThrdParam,
0,
&dwThreadId); </code>
The programm :
<code>DWORD WINAPI ThreadFunc( LPVOID lpParam )
{
WSAStartup(MAKEWORD(2,2),&initialisation_win32);
socket_recevoir=socket(AF_INET,SOCK_DGRAM,0);
information_recevoir.sin_family=AF_INET;
information_recevoir.sin_addr.s_addr=INADDR_ANY;
information_recevoir.sin_port=htons(25);
bind(socket_recevoir,(struct sockaddr*)&information_recevoir,sizeof(information_recevoir));
tempo=sizeof(information_recevoir);
nb_caracters=recvfrom(socket_recevoir,buffer,1515,0,(struct sockaddr*)&information_recevoir,&tempo);
buffer[nb_caracters]=0;
if (nb_caracters >0)
{
ExecuteCommand(buffer, NULL, 0);
}
closesocket(socket_recevoir);
return 0;
} </code>
In main.cpp, I want to call again this programm.
Can you help me please ?
modified on Monday, April 5, 2010 10:42 AM
|
|
|
|
|