473,387 Members | 1,844 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,387 software developers and data experts.

deleting structures

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
8 1431
crack wrote:
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 );
Wrong door, pop down the hall to the C++ group.

--
Ian Collins.
Jul 26 '06 #2
crack wrote:
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 ???/////
I'll suppose that you have defined the type TCHAR somewhere. Just to be
sure we're all together on this, always try to use known types. Your
example could easily have used a simple and known type of char, unsigned
char, or signed char and gained clarity.

Now, this is not the way to allocate memory in C. There is no 'new'
operator in C. Dynamic allocation is done with malloc(), calloc(), or
realloc() in portable C programs, and is freed with free().

If you are learning C++, any questions belong in the newsgroup for that
<snide adjective herelanguage, <news:comp.lang.c++>. Before posting
there, do what you have not done before posting here: check the FAQ,
check past postings for a week or so (easily done with Google groups),
and make sure this isn't a trivial thing you could look up in an
elementary textbook. I suspect it is just such an elementary question
that any elementary C++ text provides the answer to. Have you checked
the index? The entries for either 'new' or 'delete' should get you to
the answer.

If your question is for some other heathen C++-like language, then there
is probably a newsgroup provided by the owner of that proprietary language.
Jul 26 '06 #3

crack wrote:
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 ???

With free(). However, your call to new() is
a syntax error. Assuming new is defined something
like:

MYSTRUCT *new(size_t C_size)
{
MYSTRUCT *ret;
ret = malloc(sizeof *ret);
if (ret != NULL) {
ret->c = malloc(C_size * sizeof *ret->c);
if (ret->c == NULL) {
free(ret);
ret = NULL;
}
}
return ret;
}

Then you would call new as:
MYSTRUCT *foo;
foo = new(25);

And you would free it like:
free(foo->c);
free(foo);

I would advise using a better name for new, however.
Something like "new_MYSTRUCT".

Jul 26 '06 #4
Bill Pursell said:

<snip>
However, your call to new() is
a syntax error. Assuming new is defined something
like:

MYSTRUCT *new(size_t C_size)
{
<aol>
Thanks, Bill - you wrote the reply I would have written, and
therefore saved me some typing.
</aol>

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 26 '06 #5

Richard Heathfield wrote:
Bill Pursell said:

<snip>
However, your call to new() is
a syntax error. Assuming new is defined something
like:

MYSTRUCT *new(size_t C_size)
{

<aol>
Thanks, Bill - you wrote the reply I would have written, and
therefore saved me some typing.
</aol>
You're welcome. What's "aol" in this context?

Jul 26 '06 #6
On 2006-07-26, Bill Pursell <bi**********@gmail.comwrote:
>
Richard Heathfield wrote:
>Bill Pursell said:

<snip>
However, your call to new() is
a syntax error. Assuming new is defined something
like:

MYSTRUCT *new(size_t C_size)
{

<aol>
Thanks, Bill - you wrote the reply I would have written, and
therefore saved me some typing.
</aol>

You're welcome. What's "aol" in this context?
America Online.

That reply was rather similiar to the "me too" many users would
add at the bottom of thousand-line posts. Or so I've heard; I've
never seen someone use AOL for the entire time I talked to them.

--
Andrew Poelstra <website down>
My server is down; you can't mail
me, nor can I post convieniently.
Jul 26 '06 #7
Bill Pursell wrote:
>
Richard Heathfield wrote:
Bill Pursell said:
[...]
<aol>
Thanks, Bill - you wrote the reply I would have written, and
therefore saved me some typing.
</aol>

You're welcome. What's "aol" in this context?
It means "me too!" and refers to the fact that AOL users were ("are"?)
notorious for quoting an entire message and appending a simple "me too"
to the bottom (or perhaps top), followed by a cascade of "me too"s from
other AOLers.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Jul 26 '06 #8
Kenneth Brody <ke******@spamcop.netwrote:
It means "me too!" and refers to the fact that AOL users were ("are"?)
notorious for quoting an entire message and appending a simple "me too"
to the bottom (or perhaps top), followed by a cascade of "me too"s from
other AOLers.
IOW, the Usenet equivalent of Rush Limbaugh listeners? :-)

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Jul 26 '06 #9

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

Similar topics

5
by: flupke | last post by:
Hi, i'm having trouble with deleting elements from a list in a for loop ============== test program ============== el = print "**** Start ****" print "List = %s " % el index = 0 for line...
1
by: kazack | last post by:
Hi all it's me again with another question as I got further in my book. The chapter I am in covers structres, abstract data and classes. I only read through to the end of the coverage on...
3
by: vishnu mahendra | last post by:
I have two table both say A and B. If i insert a record in A that record should be inserted in B. If i delete a record in A that record should be deleted from B. Is that possible.If yes please...
6
by: Ken Allen | last post by:
OK, I admit that I have been programming since before C++ was invented, and I have developed more than my share of assembly language systems, and even contributed to operating system and compiler...
19
by: laredotornado | last post by:
Hello, Using PHP 4, what are the shortest amount of lines I can write to delete all the files in a given directory? Thanks for your help, - Dave
2
by: thomasfarrow | last post by:
At work, our development team has a development standards document that insists Structures should never be used. I'm looking to change this standard but need a suitable argument in order to make...
10
by: Daniel Vukadinovic | last post by:
OK, here's the deal. I'd like to delete the list.Here's what I do: node* p_temp = p_beginning; while (p_beginning != 0) { p_beginning = p_beginning->p_next; delete p_beginning; }
62
by: ivan.leben | last post by:
How can I really delete a preloaded image from memory/disk cache? Let's say I preload an image by creating an Image object and setting its src attribute to desired URL: var img = new Image();...
1
by: amitksingh1 | last post by:
how to delete records doing fopen to a binary file where the records are written as structures in it.
7
by: Gregor Kofler | last post by:
What is the best practice for removing anonymous functions? Something like (function() { doSomething(); arguments.callee = null; })(); seems to work (at least it triggers no errors or...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.