Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > where is the end of free()?

Reply
Thread Tools

where is the end of free()?

 
 
Netocrat
Guest
Posts: n/a
 
      10-22-2005
On Fri, 21 Oct 2005 17:20:18 +0000, Default User wrote:
> Pierre Maurette wrote:
>> Default User, le 21/10/2005, a écrit :
>> > Pierre Maurette wrote:

>
>> > > C++ give an error whithout the cast.
>> >
>> > So? This is not C++;

>> My english is so bad. I prefer to b concise.

>
> Your English would improve automatically by not using strange
> abreviations.
>
>> And you seem to need verbose mode: Maybe

>
> "Maybe"? Maybe what? I certainly could use more verbosity here, as I
> have no idea what you mean.


You snipped the subsequent quotes to which "maybe" applied. I believe
that what Pierre wrote translates to this:

Maybe the reason I wrote "C++ give an error whithout the cast." is because
the OP wrote "I supposed that the compiler would give a warning to the
statement without a cast."

i.e. he was informing the OP of an alternate situation in which the
supposition holds.

[...]
--
http://members.dodo.com.au/~netocrat
 
Reply With Quote
 
 
 
 
Artie Gold
Guest
Posts: n/a
 
      10-22-2005
Razzer wrote:
> Christopher Benson-Manica wrote:
>
>>Thomas Zhu <(E-Mail Removed)> wrote:
>>
>>>does the system free n mem-units or n-1 mem-units?

>>
>>Neither. If you pass a pointer to free() that was not returned by a
>>call to malloc(), you get "undefined behavior" - in other words,
>>absolutely anything may happen at that point.

>
>
> Which techincally means that the implementation could free "n mem-units
> or n-1 mem units". Not that you should rely on this behavior, but I
> just want to point out on the broad abilities of a computer to do
> mischief .
>

Erm, more likely it would free an amount of storage that was not
intended. Or crash. Or do things of which we shall not speak. Or
*appear* to work -- at least until the worst possible moment.

Corruption can be like that.

Cheers,
--ag

--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com (new post 8/5)
http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"
 
Reply With Quote
 
 
 
 
ashu
Guest
Posts: n/a
 
      10-22-2005
hi, would you please tell me, what is the meaing of (n * sizeof(int)).
is it means n times sizeof(int) or some pointer???

 
Reply With Quote
 
ashu
Guest
Posts: n/a
 
      10-22-2005
what is cast. would you please describe the whole question with answer
to me...Madhav.
as i'm new to the language.

 
Reply With Quote
 
Joe Wright
Guest
Posts: n/a
 
      10-22-2005
ashu wrote:
> what is cast. would you please describe the whole question with answer
> to me...Madhav.
> as i'm new to the language.
>

The cast is an explicit mechanism to force a type conversion. We won't
describe the whole thing here. Look it up in your C book. If you don't
have one, get one. This newsgroup is not a substitute for a C book.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
 
Reply With Quote
 
Niklas Norrthon
Guest
Posts: n/a
 
      10-24-2005
"Default User" <(E-Mail Removed)> writes:

> Pierre Maurette wrote:
>
> > Thomas Zhu, le 21/10/2005, a écrit :
> > > Thanks a lot.
> > >
> > > I've got it.
> > > I supposed that the compiler would give a warning to the statement
> > > without a cast.
> > > But I was wrong.

>
> > C++ give an error whithout the cast.

>
> So? This is not C++;
>
> > IMHO, it is not a mortal sin to cast the malloc() return in both C
> > and C++.

>
> You shouldn't be using malloc() in C++. You should be using new.
> Writing code to be cross-language compatible is usually a waste of time
> and inefficient, outside of a few library developers.


No rule without exceptions...
Last week I used malloc in C++ for the first time in the 15 years I've
been playing with the language... I had a buffer which I needed to
shrink every once in a while, so I saved lots of CPU cycles switching
from new[] and delete[] to malloc, realloc and free.

IMHO opinion it is a mortal sin to use any cast at all when they are
not absolutely necessary, and a sin, but forgivable, to use casts
where they are necessary. We are all sinners of course.

/Niklas Norrthon
 
Reply With Quote
 
Marc Boyer
Guest
Posts: n/a
 
      10-24-2005
Niklas Norrthon <(E-Mail Removed)> a écrit*:
> "Default User" <(E-Mail Removed)> writes:
>> Pierre Maurette wrote:
>> > Thomas Zhu, le 21/10/2005, a écrit :
>> > > Thanks a lot.
>> > >
>> > > I've got it.
>> > > I supposed that the compiler would give a warning to the statement
>> > > without a cast.
>> > > But I was wrong.

>>
>> > C++ give an error whithout the cast.

>>
>> So? This is not C++;
>>
>> > IMHO, it is not a mortal sin to cast the malloc() return in both C
>> > and C++.

>>
>> You shouldn't be using malloc() in C++. You should be using new.
>> Writing code to be cross-language compatible is usually a waste of time
>> and inefficient, outside of a few library developers.

>
> No rule without exceptions...
> Last week I used malloc in C++ for the first time in the 15 years I've
> been playing with the language... I had a buffer which I needed to
> shrink every once in a while, so I saved lots of CPU cycles switching
> from new[] and delete[] to malloc, realloc and free.


Using a std::vector and resize was not adapted in your context ?

> IMHO opinion it is a mortal sin to use any cast at all when they are
> not absolutely necessary, and a sin, but forgivable, to use casts
> where they are necessary.


As I often say 'follow this advice until you have a good
reason to do otherwise'.

Marc Boyer
 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      10-24-2005
Netocrat wrote:

> On Fri, 21 Oct 2005 17:20:18 +0000, Default User wrote:
> > Pierre Maurette wrote:
> >> Default User, le 21/10/2005, a écrit :
> >> > Pierre Maurette wrote:

> >
> >> > > C++ give an error whithout the cast.
> >> >
> >> > So? This is not C++;
> >> My english is so bad. I prefer to b concise.

> >
> > Your English would improve automatically by not using strange
> > abreviations.
> >
> >> And you seem to need verbose mode: Maybe

> >
> > "Maybe"? Maybe what? I certainly could use more verbosity here, as I
> > have no idea what you mean.

>
> You snipped the subsequent quotes to which "maybe" applied. I believe
> that what Pierre wrote translates to this:


I snipped nothing else that he wrote following that line. The only
thing following the "maybe" was some old quotes that he left in.


> Maybe the reason I wrote "C++ give an error whithout the cast." is
> because the OP wrote "I supposed that the compiler would give a
> warning to the statement without a cast."


You are inferring something from the word "maybe" and some unsnipped
quotes. As I said, he needed to say what he meant. I'm not a tea-leaf
reader (or old quote diviner).

> i.e. he was informing the OP of an alternate situation in which the
> supposition holds.


Nonsense. Complete supposition.




Brian
 
Reply With Quote
 
Netocrat
Guest
Posts: n/a
 
      10-25-2005
On Mon, 24 Oct 2005 17:28:06 +0000, Default User wrote:
> Netocrat wrote:
>> On Fri, 21 Oct 2005 17:20:18 +0000, Default User wrote:
>> > Pierre Maurette wrote:
>> >> Default User, le 21/10/2005, a écrit :
>> >> > Pierre Maurette wrote:
>> >
>> >> > > C++ give an error whithout the cast.
>> >> >
>> >> > So? This is not C++;
>> >> My english is so bad. I prefer to b concise.
>> >
>> > Your English would improve automatically by not using strange
>> > abreviations.
>> >
>> >> And you seem to need verbose mode: Maybe
>> >
>> > "Maybe"? Maybe what? I certainly could use more verbosity here, as I
>> > have no idea what you mean.

>>
>> You snipped the subsequent quotes to which "maybe" applied. I believe
>> that what Pierre wrote translates to this:

>
> I snipped nothing else that he wrote following that line. The only
> thing following the "maybe" was some old quotes that he left in.


Those old quotes are the ones to which I referred.

>> Maybe the reason I wrote "C++ give an error whithout the cast." is
>> because the OP wrote "I supposed that the compiler would give a
>> warning to the statement without a cast."

>
> You are inferring something from the word "maybe" and some unsnipped
> quotes.


In the absence of mind-reading, inference is partly what communication is
about, no?

> As I said, he needed to say what he meant. I'm not a tea-leaf
> reader (or old quote diviner).


Right, I only stepped in because it was apparent his confidence in
his English skills prevented him from doing that to the point that you
could readily understand, however with a little interpretation his meaning
became clear to me.

>> i.e. he was informing the OP of an alternate situation in which the
>> supposition holds.

>
> Nonsense. Complete supposition.


It's a supposition, but it does make sense - reread his post assuming that
"Maybe" had been followed by a colon as "accounts for" had. Also note
that it appeared on a new line in the original whereas in your quoted
version "Maybe" appears on the same line as the preceding sentence.

--
http://members.dodo.com.au/~netocrat
 
Reply With Quote
 
Niklas Norrthon
Guest
Posts: n/a
 
      10-25-2005
Marc Boyer <(E-Mail Removed)> writes:

> Niklas Norrthon <(E-Mail Removed)> a écrit*:
> >
> > No rule without exceptions...
> > Last week I used malloc in C++ for the first time in the 15 years I've
> > been playing with the language... I had a buffer which I needed to
> > shrink every once in a while, so I saved lots of CPU cycles switching
> > from new[] and delete[] to malloc, realloc and free.

>
> Using a std::vector and resize was not adapted in your context ?


No, resize just erases the elements. It doesn't return anything to the
memory manager.

/Niklas Norrthon
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with switch configuration, ( 3 3550's, 5 2950's end to end ) ec Cisco 3 07-25-2006 10:30 AM
using translate as a REAL end-to-end x25 to tcp gateway? RedRat Cisco 1 02-01-2006 09:21 PM
Re: Private LAN: why should the gateway address be at the low end of the range, rather than at the high end. Ted Jones Cisco 11 11-04-2005 05:56 AM
Measure delay end-to-end Dave Cisco 1 07-20-2004 12:51 PM
is there a difference between CIR and CIR+end to end clear channel connection? ike lozada Cisco 0 05-27-2004 02:34 AM



Advertisments