stoffel, sorry, i dont understand what you mean, perhaps it is because i am not so good in english.
what do you mean with "copied by value", or how can i solve the problem?
operators new/delete in constructor/destructor
Class a; // This allocates memory on construction
Class b; // This also allocates memory on construction
a = b; // a and b now use the memory b was pointing to
// a and b get destructed, and free the same data (crash!)
// also the memory a used before is leaked.
Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
Class b; // This also allocates memory on construction
a = b; // a and b now use the memory b was pointing to
// a and b get destructed, and free the same data (crash!)
// also the memory a used before is leaked.
Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
siaspete, that''s not possible in my program, becaus i dont do anything with my class.
just:
void main()
{
while(1)
{
example var;
}
}
just:
void main()
{
while(1)
{
example var;
}
}
my application is multithreaded. could that be the problem?
and another question:
which runtime library do i have to select in the "project settings -> Code generation", or what are the differences. can anybody explaine that?
-multithreaded
-multithreaded DLL
-debug multithreaded
-debug multithreaded DLL
and another question:
which runtime library do i have to select in the "project settings -> Code generation", or what are the differences. can anybody explaine that?
-multithreaded
-multithreaded DLL
-debug multithreaded
-debug multithreaded DLL
Kudi:
"Pass-by-value" means that the object is being passed into a function by value instead of by pointer or reference (which are both referred-to as "pass-by-reference", which is admittedly confusing).
Example of how your program will crash with your object constructed as you say:
Now, this will crash instantly. If it''s crashing after a while, then something else is going on. If possible, you might have to show us your code of the main loop in its entirety, and at least the function declarations of every function you call.
"Pass-by-value" means that the object is being passed into a function by value instead of by pointer or reference (which are both referred-to as "pass-by-reference", which is admittedly confusing).
Example of how your program will crash with your object constructed as you say:
void foo (example e) // pass-by value{ // doesn''t really need to do anything..}void main (){ while (true) { example e; // ctor called, data allocated at 0x12345678 foo (e); // creates a copy of data by value--now there // is a second example object with data at // 0x12345678 // as function returns, object is destroyed and // 0x12345678 is deleted } // end of loop; ~example is called on e, trying to delete // 0x1234567, but it''s already been deleted. Crash.}
Now, this will crash instantly. If it''s crashing after a while, then something else is going on. If possible, you might have to show us your code of the main loop in its entirety, and at least the function declarations of every function you call.
show us the real code, please.
also why do you need to do 'new'?
works just as well as long as SIZE is a constant, known at compile time.
if you're using c++ and need a variable size try using vector<char> as that can be resized and won't cause you memory allocation issues.
[edited by - petewood on October 7, 2002 1:51:41 PM]
also why do you need to do 'new'?
char data[SIZE]
works just as well as long as SIZE is a constant, known at compile time.
if you're using c++ and need a variable size try using vector<char> as that can be resized and won't cause you memory allocation issues.
[edited by - petewood on October 7, 2002 1:51:41 PM]
thanks for all your answers, but i think i know what my mistake was (i am still not sur, because it is a runtime error and it sometimes takes 10 minutes until it appears). i didn''t chose multihreaded in /project settings/code generation/runtime library
actually i am a bit confused, because i think i had activated it once it and it still didnt function, but i will see. or it also could be the printf function which needs mutexes?
actually i am a bit confused, because i think i had activated it once it and it still didnt function, but i will see. or it also could be the printf function which needs mutexes?
Many standard library functions are not threadsafe. That''s what the multi-threaded runtime is for. Using the single-threaded runtime can cause crashes or undefined behaviour at seemingly random times.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement