where is the end of free()?

N

Netocrat

Your English would improve automatically by not using strange
abreviations.


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

[...]
 
A

Artie Gold

Razzer said:
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
 
A

ashu

hi, would you please tell me, what is the meaing of (n * sizeof(int)).
is it means n times sizeof(int) or some pointer???
 
A

ashu

what is cast. would you please describe the whole question with answer
to me...Madhav.
as i'm new to the language.
 
J

Joe Wright

ashu said:
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.
 
N

Niklas Norrthon

Default User said:
So? This is not 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
 
M

Marc Boyer

Niklas Norrthon said:
Default User said:
So? This is not 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
 
D

Default User

Netocrat said:
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
 
N

Netocrat

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

Niklas Norrthon

Marc Boyer said:
Niklas Norrthon said:
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
 
D

Default User

Netocrat wrote:

Those old quotes are the ones to which I referred.

There was no indication from new text that the old text was being
reiterated versus merely left behind. As the OP could barely write a
legible post, the second assumption is as valid as the first.

As I said, he needed more text to remove ambiguity.
 
N

Neil Cerutti

Marc Boyer said:
Niklas Norrthon said:
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.

In that case, you need the swap-shrink trick.

Assuming v is the vector of int you want to shrink:

vector<int>(v).swap(v);

See URL:http://www.gotw.ca/gotw/054.htm.
 
F

Flash Gordon

Neil said:
Marc Boyer said:
Niklas Norrthon <[email protected]> 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.

In that case, you need the swap-shrink trick.

Assuming v is the vector of int you want to shrink:

vector<int>(v).swap(v);

See URL:http://www.gotw.ca/gotw/054.htm.

Can you please take this discussion somewhere it is topical, such as
comp.lang.c++

FU set
 

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

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top