|
Try this ................
int main()
{
char *name = getmestring(); --> modify this line
cout<<name<<endl;
if(name !="NULL)
{
" name="NULL;" ---=""> Add this line
delete [] name; --> this is causing the debug assertion failed..
}
}
Inform me if success...
Ashutosh
|
|
|
|
|
int main()
{
char *name = getmestring(); --> modify this line
cout<<name<<endl;
if(name != NULL)
{
name = NULL; ---> Add this line
delete [] name; --> this is causing the debug assertion failed..
}
}
assigning name =NULL and then deleting it will give u an error since u r trying to delete a block that points to the null address!!!!rather the code should be more like.....
int main()
{
char *name = NULL;
name = getmestring();
cout<<name<<endl;
if(name != NULL)
delete [] name;
}
cheerz!
dont want,dont want thinking,climbing on head and jumping grass!
(venda venda ennu vicharikumbol thellayill keyaree chadunnoda pulle!)
-- modified at 3:35 Wednesday 15th February, 2006
|
|
|
|
|
namaskaaram wrote: assigning name =NULL and then deleting it will give u an error since u r trying to delete a block that points to the null address!!!!
No it won't. It won't do as intending, but delete ing a NULL pointer is a perfectly valid operation - it does not cause errors.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
But then again there will be a memory leak
codito ergo sum
|
|
|
|
|
Usually, but that's not the point I was making. His statement was that delete ing a NULL pointer causes an error because the pointer is NULL. This is not correct.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I know,
I was just trying to point out for naguu that altough setting a pointer to NULL and then deleting wont cause an error it will cause a memory leak. Which was (one of) his first problems.
To conclude:
char * getmestring()
{
char *str = new char[20];
strcpy(str, "myname");
return str;
}
int main()
{
char *name = getmestring();
cout<<name<<endl;
if(name != NULL)
{
delete [] name;
}
}
codito ergo sum
|
|
|
|
|
Fair enough
BadKarma wrote: //char name = getmestring();char *name = getmestring();
I assumed here he just typed into the message wrong - otherwise his code wouldn't have even compiled, much less got memory leaks
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
.....yeah just tried it out!....ur right! thankz!
hmm,doesnt the location pointed by the pointer gets lost when made null?,so i believe we loose the dynamically created objects location dont we?so there is a mem leak right?;)
anywayz thanx for the correction!
cheerz!
dont want,dont want thinking,climbing on head and jumping grass!
(venda venda ennu vicharikumbol thellayill keyaree chadunnoda pulle!)
|
|
|
|
|
There is usually a memory leak when you delete NULL . Not always, however. if you have a class that allocates memory using new , it's reasonably standard practice to delete it in the destructor. If you have another cleanup routine that delete s the pointer (and then sets it to NULL - always an excellent idea), then the delete in the destructor doesn't need to have a if (!NULL) check around it - it makes no difference whether the pointer is NULL or not.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
namaskaaram wrote: assigning name =NULL and then deleting it will give u an error since u r trying to delete a block that points to the null address!!!!
rather the code should be more like.....
Do you know basic of pointers.........?
Ashutosh
|
|
|
|
|
namaskaaram wrote: int main(){char *name = NULL; name = getmestring(); cout<<name<<endl;if(name !="NULL)delete" []="" name;}<="" blockquote="">
change it to
if(name != NULL)
delete [] name;
name=NULL
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Since you are using C++, why mess with char at all? Use std::string instead and you won't have these silly memory issues.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
Hello! I'm a c++ beginner, and i'm trying to encrypt a simple text file, but, as I search in the internet, there are a lot of algorithms that I could use... so I'm a little bit confused... Can you tell me wich one is the best for me?
The file can be encrypted / decrypted with a Key or passhrase. Maybe using a symmetric algorithm ?
Well, I hope you could help on this..... Thanks a lot!
Aby Skaria
|
|
|
|
|
Jean-loup Gailly algo!.....u can get their free lib!....
click this[^]
dont want,dont want thinking,climbing on head and jumping grass!
(venda venda ennu vicharikumbol thellayill keyaree chadunnoda pulle!)
|
|
|
|
|
hello..! Well most often in encryption the longer the key the better. So that brute force will not be applied on your encryption algorithm. You should consider security threats before deciding which one to use.
-------------------Life is simple, You just complicate things --------------
|
|
|
|
|
Hi,
I have build the application using MFC, VC++ 6 on Windows XP. It is runnign fine in on my system. But it get crashed on the cleint side (operating system Win2K) but sometimes it worked fine .cleint is too far from me, I cannot debugg it personaly over there.
How can I check it that at which pont it is crashing.
Thanks
Regards.
|
|
|
|
|
First check for any memory leak in your project-- u can use CMemoryState class for that
If it is ok the check for resource leak.
if it is ok the ckeck all the syncronization objects u r using , is there is any chance of deadlock , it may be possible if u r using timer function fo syncronization object
for locking and unlocking.
CHeck it out ...
I will try for other than these reasons for this
Ashutosh
|
|
|
|
|
Try this article. It has helped me a couple of times.
If you follow it, you will be able to pinpoint the specific line in a specific source file where the program crashed.
In a release build, with minimum overhead.
http://www.codeproject.com/debug/mapfile.asp[^]
|
|
|
|
|
Hi,
I have created a DLL which has certain shared variables/functions. I have accessed the same DLL in another workspace, when I run the application I am facing the following error. Can anone pls. help me out.
Linking...
AccessRegDLLDlg.obj : error LNK2005: _nVar_Subbu already defined in AccessRegDLL.obj
Debug/AccessRegDLL.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
The code in the DLL is:
extern "C" {
__declspec(dllexport) int TestDLLFunction();
__declspec(dllexport) int GetValue();
#pragma data_seg("SHARED")
int nVar_Subbu = 1;
#pragma data_seg()
};
Rgds,
Arun.
|
|
|
|
|
Is this code in the header file? Are you including it from more than one .cpp file?
In a header file, mark the variable as extern (without the initialisation), and declare the variable as normal in a .cpp file.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Yes, the code declaring variables and functions to be exported is in the header file of the dll.
I have included it using:
#include "..\RegDLLTest\RegDLLTest.h"
but for using a dll as shared i must initiaize the value in the dll to some value o/w the dll itlself will not compile.
Thanks for your response but i still need help.
It's not working.
---Arun.
|
|
|
|
|
The multiply defined error is occurring because you're defining the variable in your header file and including it in two locations. You need to split the declaration as I said:
Header File:
extern int nVar_Subbu; .cpp File
int nVar_Subbu = 1; Only compile this .cpp file in your DLL.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
try makeing the variable static
static int nVar_Subbu = 1;
nav
|
|
|
|
|
Oh! Thanks Naveen it worked, but can you pls. explain if possible why is static needed.
Rgds,
Arun.
|
|
|
|
|
Hi,
My intention of making the shared dll was that the data or a varibale that is incremented in one exe would reflect in the other. but, making it static the varables have become independent.
Scenario:
I have two exe's accessing the same variable:
i.e "nVar_Subbu" which was initially 1, I have incremented the value of this variable in one exe to 2, when accessed from the other exe it is till showing 1 instead of 2. How to go about this, can anyone help me out pls.
Rgds,
Subbu.
|
|
|
|