473,399 Members | 2,278 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,399 software developers and data experts.

deleting structure

Hi ,
i would like to delete a structure of type
typedef struct Mystruct
{
int a;
TCHAR b[256];
TCHAR*c;
}MYSTRUCT

i am a allocating memory as
MYSTRUCT *Mystr = new (MYSTRUCT );

?but how to free this memeory ???/////

Jul 26 '06 #1
5 11933
crack wrote:
Hi ,
i would like to delete a structure of type
typedef struct Mystruct
{
int a;
TCHAR b[256];
TCHAR*c;
}MYSTRUCT
Avoid C style declarations, use

struct MYSTRUCT {};

Often all caps names are reserved for macros.
i am a allocating memory as
MYSTRUCT *Mystr = new (MYSTRUCT );
You don't have to add the parenthesis here.
?but how to free this memeory ???/////
delete Mystr;

--
Ian Collins.
Jul 26 '06 #2
as i am getting a ecception after it.
but there is pointer ,how wil free.

Jul 26 '06 #3
crack wrote:
as i am getting a ecception after it.
but there is pointer ,how wil free.
After what? Please quote the context you are replying to.

What sort of exception? Please post some code that reproduces the problem.

--
Ian Collins.
Jul 26 '06 #4
Hello,

I assume that you used TCHAR*c;
If yes, you'll need to free it first before delete the whole struct.

Cheers,
Jari

crack wrote:
as i am getting a ecception after it.
but there is pointer ,how wil free.
Jul 26 '06 #5

"Jari" <ja*******@yahoo.co.ukwrote in message
crack wrote:
>as i am getting a ecception after it.
but there is pointer ,how wil free.
>
I assume that you used TCHAR*c;
If yes, you'll need to free it first before delete the whole struct.
[Please don't top-post. Place comments in-line with or following what
you're replying to. I've rearragned it.]

Note that your suggestion refers to how to avoid a memory leak of the data
pointed to by that pointer (which would best be handled by a destructor, by
the way). The original poster said there's an exception, which would be
caused by something other than forgetting to call delete on that member.
(But as there's no code shown where the class is used, it's impossible to
know what causes the exception at this point.)

-Howard
Jul 26 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Abhijeet | last post by:
I was just toying around idea of deleting this from a member function. Was expecting that any acess to member variable or function after deleting sould give me dump(segmetation violation).Cause now...
1
by: John | last post by:
Hi All, When I delete the last record from my dataset and then WriteXML() to the file; the Table itself, in the xml file, is removed. I need to prevent the table structure from being deleted if...
4
by: Fughal | last post by:
Hi, I have a big DB2 database and I need this database without any Data in it for testing something. I have made a backup of these db and restore it on a testing system. My Problem is now how...
1
by: Coy Howe | last post by:
This one seems bizarre! We have a database consisting of a main table and 12 - 15 "sub" tables, which are connected via cascading relationships. The database performs many complex calculations...
6
by: Martin Bischoff | last post by:
Hi, I'm creating temporary directories in my web app (e.g. ~/data/temp/temp123) to allow users to upload files. When I later delete these directories (from the code behind), the application...
1
by: tsuki | last post by:
Hello, I have a problem concerning DOM and XML. The structure of my xml is the following: <?xml version="1.0" encoding="utf-8"?> <website> <language1> <seite> <bereich1>
6
by: yxq | last post by:
Hello, The File.Delete(VS2005) function can not delete file on Vista-64bit, why? And, what changes of API between 32-bit and 64-bit? Thank you
2
by: maynard | last post by:
I have defined a template class (tree data structure) that uses dynamic memory and has properly implemented ctor's, dtor and assignment operator. I can observe the address of my tree object prior...
1
by: arv6004u | last post by:
Hi, I have created Map Data stacture. Each map Entry contains hostname and it's value. I have traversed the map using iterator then i want to delete specific hostname entry and to change the...
5
by: cham | last post by:
Hi, I am working on c++ in a linux system ( Fedora core 4 ), kernel version - 2.6.11-1.1369_FC4 gcc version - 4.0.0 20050519 ( Red Hat 4.0.0-8 ) In my code i am creating a vector to store...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.