Simple code leads to segfault.. help

R

Richard Heathfield

Keith Thompson said:
Are you assuming that memory that has been free()d *will* be reclaimed
by the operating system?

I don't see how you can reasonably infer that Martin is assuming any such
thing. If anything, he is asserting the opposite - i.e. that there is no
reason to assume it.
 
R

Richard Heathfield

Martin Ambuhl said:
You asked a question that imputed to me an assumption. It was an
assumption I never made, about an issue which I never speculated on.

True enough, but...
You made the assumption out of your own imagination: you answer it. You
have repeatedly pulled this puerile parlor trick of imputing to people
assumptions they never made and then demanding answers, hiding behind
the obvious facade of "I just asked a question." This may impress the
other kiddies at your day care center, but honest adults don't do this.
Go back to your sandbox.

....I think this is an over-reaction.

Over-reactions do, of course, make for lively and sometimes entertaining
reading, but nevertheless they rarely reflect credit on their authors.

I suggest you guys both get yourselves down to the fridge and see if there's
any beer left. :)
 
J

Joe Wright

Richard said:
Joe Wright said:



That kind of thinking costs money, when main() becomes foo(), and foo() is
called in a loop. Fortunately, money is conserved, and the maintenance
programmer's family gets buns for tea.

I'm trying to read the paragraph above. How should main() become foo()?
I'm probably as anal as anyone about pairing malloc() and free() calls
within my programs. It's simply good practice.

That malloc() stuff can call sbrk() stuff to have the OS allocate memory
to our process, our free() stuff probably doesn't cause the OS to
reclaim any memory. On termination of our process, the OS will reclaim
all memory allocated to it.
 
M

Martin Ambuhl

Keith said:
Please try a little reading comprehension. I asked a question.
Rather than answering it, you chose to make assumptions about what was
behind it.

Idiot! I answered your question. To repeat your question:
Are you assuming that memory that has been free()d *will* be reclaimed
by the operating system? If so, what is your basis for that
assumption?

You are obviously too stupid to understand, so I will make it as clear
as possible: I do not make that assumption. Got it?

You made up the assumption, asked me (as if it were somehow related to
anything I wrote, which it is not) if I held it. I was clear that the
source of that assumption was you, not me. I never wrote anything on
which your baby pseudo-cross examination could be based. Go away.
 
M

Martin Ambuhl

Richard said:
...I think this is an over-reaction.

Over-reactions do, of course, make for lively and sometimes entertaining
reading, but nevertheless they rarely reflect credit on their authors.

But I answered his question: whether I assumed <Keith Thompson
fabrication>. He then claimed I had not answered it. This can only be
true if I _did_ make his assumption and then had refused to answer his
second question. But that second question assumes an answer to the
first question. His first question was dishonest: his claim that I did
not answer was even more dishonest.
 
R

Richard Heathfield

Joe Wright said:
I'm trying to read the paragraph above. How should main() become foo()?

You write what you think is an application. It has a main() and everything.
It's huge. Easily a quarter of a million lines. It goes into production. A
few years later, someone spots that it isn't /really/ an application - it's
just a library routine! And so they s/main/foo/ (or some more fitting name,
obviously), and call the thing over and over again, in a loop. Suddenly,
memory is dripping out of the side-panels and forming puddles under the
raised floor.

When I was at MumbleCo, I was working on just such a program. Unfortunately,
at the time I didn't have the clout to make the project lead realise the
importance of good housekeeping. Along with quite a few others, I worked on
that program for over a year, and then it finally went in, and I wandered
off to greener pa$ture$, as they say.

Some years later, I found myself working for CoughCo, who had paid MumbleCo
a significant sum of money for the program (I don't know whether it was a
transfer of ownership or a mere licensing deal, and it doesn't really
matter for the purpose of this account). It was no coincidence that CoughCo
hired me, of course. They were after my experience of the program.

Anyway, CoughCo decided that this wasn't a program really. It was just a
subroutine. Admittedly, at 250KLOC or so, it was a rather *big* subroutine,
but a subroutine nonetheless. And so they gave main a new name, and called
it from their own main. In a loop. And that's when the memory usage hit the
ceiling.

Good housekeeping isn't just pedantry in practice. It's part of defensive
programming.
 
K

Keith Thompson

Richard Heathfield said:
Martin Ambuhl said:

True enough, but...

No, not really.

If neither Martin and Richard understood what I was trying to say, I
probably didn't write clearly enough. I honestly thought that my
meaning was clear.

I'll post again later and try to explain what I actually meant.

Martin: this was a simple misunderstanding, entirely unintentional on
my part. I have not deliberately forced any assumption on you.

Your accusation that I have been dishonest is stupid and offensive.
 
R

Richard Tobin

Martin Ambuhl said:
You asked a question that imputed to me an assumption. It was an
assumption I never made, about an issue which I never speculated on.

Your post - in response to an assertion that it was unnecessary to
free memory before exiting, because the OS will do it - could quite
naturally be taken as implying that you *should* free memory, because
the OS won't necessarily do it. That would only make sense if the OS
reclaimed memory that you freed, which is equally susceptible to your
rather rude comment:
Unless you can
show where the standard for C requires this, keep your non-portable,
system-specific opinions to yourself.

Now perhaps you didn't mean to imply that you should free memory, but
I don't think you can blame people for inferring that.

-- Richard
 
A

Andrew Poelstra

Spiros Bousbouras said:
Does your code make provisions for every occurence allowed
by the standard no matter how improbable ? Do you for
example check the return value of printf in your code ? I doubt
it. Do you consider more probable that some operating system
won't reclaim memory than that printf will return a negative
value ? I don't.

If my code depended on printf() succeeding, I would indeed check
the return value. However, most printf() statements provide no
real value to the program: they just output information on how
the program runs, nothing more.

Considering that my system depends on having some of its memory
free (after all, it's finite!) I would free() memory before the
program terminates. Your mentality may differ.
 
A

Andrew Poelstra

Keith Thompson said:
Are you assuming that memory that has been free()d *will* be reclaimed
by the operating system? If so, what is your basis for that
assumption?

Since there's some confusion on this point:

To me it appears that this is just a question. It doesn't appear to be
making any assumptions about what the answer might be. It certainly
doesn't appear offensive in any way.
 
F

Frederick Gotham

Keith Thompson posted:
But I would advocate making any such assumptions explicit, so if
someone tries to compile the code on some exotic system that doesn't
satisfy the assumptions, the error is caught as early and as cleanly
as possible.

#if CHAR_BIT > 8
#error ......................
#endif
 
F

Frederick Gotham

Spiros Bousbouras posted:
Does your code make provisions for every occurence allowed
by the standard no matter how improbable ?


Yes.

Improbability is irrelevant.

If I say that a certain snippet is portable, I mean that that snippet is
portable according to the C89 Standard (on this newsgroup).
 
R

Richard Heathfield

Andrew Poelstra said:
Since there's some confusion on this point:

To me it appears that this is just a question. It doesn't appear to be
making any assumptions about what the answer might be. It certainly
doesn't appear offensive in any way.

No, it doesn't appear offensive to me, either. But you'd be surprised at how
easily people can take offence. Any of us. For example, you'd probably be
offended if I called you a... well, let's not go there. :)
 
R

Richard Heathfield

CBFalconer said:
However there exist systems in which free is O(n), where n is the
count of allocations made. This makes freeing everything on exit
O(n*n), and can be a real drag.

Having your application catch amnesia can be a real drag, too. If better
ways of doing the Right Thing can be found, that's fabulous, but the
absence of those better ways does not mean we should do the Wrong Thing
instead.
 
K

Kenny McCormack

Are you assuming that memory that has been free()d *will* be reclaimed
by the operating system? If so, what is your basis for that
assumption?

It makes you realize just how sad Martin Ambuhl's life must be (when you
read his hateful, hysterical posts)
 
K

Kenny McCormack

Are you assuming that memory that has been free()d *will* be reclaimed
by the operating system?

There is nothing in my post from which you can extrapolate such an
assumption.
If so, what is your basis for that
assumption?

What is your basis for trying to force assumptions onto me and then
pretending I have some obligation to justify your claimed assumption.

Please try a little honesty.[/QUOTE]

Chick fight!!!
 
K

Kenny McCormack

You asked a question that imputed to me an assumption. It was an
assumption I never made, about an issue which I never speculated on.
You made the assumption out of your own imagination: you answer it. You
have repeatedly pulled this puerile parlor trick of imputing to people
assumptions they never made and then demanding answers, hiding behind
the obvious facade of "I just asked a question." This may impress the
other kiddies at your day care center, but honest adults don't do this.
Go back to your sandbox.

Girls, girls, girls!!!

Now, kiss and make up. We forgive you.
 
K

Kenny McCormack

Richard Heathfield said:
I suggest you guys both get yourselves down to the fridge and see if there's
any beer left. :)

Agreed. Keeping in mind, of course, that the term "guys" is being used
here in its modern, generic sense.
 
K

Kenny McCormack

Your post - in response to an assertion that it was unnecessary to
free memory before exiting, because the OS will do it - could quite
naturally be taken as implying that you *should* free memory, because
the OS won't necessarily do it. That would only make sense if the OS
reclaimed memory that you freed, which is equally susceptible to your
rather rude comment:


Now perhaps you didn't mean to imply that you should free memory, but
I don't think you can blame people for inferring that.

Never argue with a pig. You won't get anywhere, and the pig likes it.
 
K

Kenny McCormack

Idiot! I answered your question. To repeat your question:

You are obviously too stupid to understand, so I will make it as clear
as possible: I do not make that assumption. Got it?

You made up the assumption, asked me (as if it were somehow related to
anything I wrote, which it is not) if I held it. I was clear that the
source of that assumption was you, not me. I never wrote anything on
which your baby pseudo-cross examination could be based. Go away.

Let's take a vote: Who should go away - Keith or Martin?
I vote neither - both are too entertaining, each in their own way.
 

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,780
Messages
2,569,611
Members
45,269
Latest member
vinaykumar_nevatia23

Latest Threads

Top