deleting structures

C

crack

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

Ian Collins

crack said:
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.
 
M

Martin Ambuhl

crack said:
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 here> language, < 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.
 
B

Bill Pursell

crack said:
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".
 
R

Richard Heathfield

Bill Pursell said:

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>
 
B

Bill Pursell

Richard said:
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?
 
A

Andrew Poelstra

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.
 
K

Kenneth Brody

Bill said:
Richard said:
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:[email protected]>
 
C

Christopher Benson-Manica

Kenneth Brody said:
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? :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,786
Messages
2,569,626
Members
45,328
Latest member
66Teonna9

Latest Threads

Top