Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Help:the problem of Ring of Josephus

Reply
Thread Tools

Help:the problem of Ring of Josephus

 
 
Flash Gordon
Guest
Posts: n/a
 
      03-07-2006
Rod Pemberton wrote:
> "Chad" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) ups.com...


<snip>

>> Why don't we check malloc() for NULL? Is malloc() this special when it
>> comes to the Ring of Josephus

>
> Do you _honestly_ think that malloc() will fail to provide 32 bytes? 4Kb?
> 64Kb? on any modern computer, miniframe or mainframe?
>
> Do you _honestly_ think that he'll be running a 64Gb "Ring of Josephus"? In
> that case, he'd definately want a linked-list.


Do you honestly think that people never run out of virtual memory? If
so, I've got news for you. I've *seen* modern PCs run out of both real
and virtual memory. Obviously this means the PC is not up to spec for
what it is being asked to do, but that does not alter the fact that it
*does* happen, and when a machine is out of memory it can fail to
allocate *one* byte because there is *no* memory available.

<snip>

>>> exit(EXIT_SUCCESS);

>
> The two important lines from the spec:
> "The exit function causes normal program termination to occur."
> "Finally, control is returned to the host environment."
>
> Returning resources to an OS, such as deallocation of the memory allocated
> by a program, is a mandatory part of the host OS's "normal program
> termination" and "control ...[being] returned to the host environment."


Not as far as C is concerned it isn't. The C standard does not care what
happens to the system after the program has terminated.

> Without it, the OS would run out of memory... Since all successful OS's
> where partly developed or influenced heavily by EE's, I doubt that there is
> a 'stupid' OS which doesn't deallocate memory.


People still use DOS and that is pretty stupid. Although I don't know if
it has this specific problem.

> Stop being inane.

--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      03-07-2006
Flash Gordon said:

> People still use DOS


Presumably you are referring to MS-DOS.

> and that is pretty stupid.


Not if it meets their needs better than the alternatives.

--
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)
 
Reply With Quote
 
 
 
 
Flash Gordon
Guest
Posts: n/a
 
      03-07-2006
Richard Heathfield wrote:
> Flash Gordon said:
>
>> People still use DOS

>
> Presumably you are referring to MS-DOS.


Or IBM-DOS or Caldera-DOS, or...

In fact, Caldera-DOS seems to be common for bootable BIOS upgrade floppies.

>> and that is pretty stupid.

>
> Not if it meets their needs better than the alternatives.


I meant that the OS is pretty stupid, not the decision to use it.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
 
Reply With Quote
 
Nelu
Guest
Posts: n/a
 
      03-07-2006

Rod Pemberton wrote:
> "Chad" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) ups.com...
>

<snip>
> > Why don't we check malloc() for NULL? Is malloc() this special when it
> > comes to the Ring of Josephus

>
> Do you _honestly_ think that malloc() will fail to provide 32 bytes? 4Kb?
> 64Kb? on any modern computer, miniframe or mainframe?
>
> Do you _honestly_ think that he'll be running a 64Gb "Ring of Josephus"? In
> that case, he'd definately want a linked-list.
>
> > Where is free()? Is the function off having an affair with teacher in
> > comp.lang.c++ ?

>
> You don't understand what exit() must do to interface properly with an OS.
>
> > > exit(EXIT_SUCCESS);

>
> The two important lines from the spec:

<snip>

Whether or not the OS knows how to cleanup after a program terminates
is not important here. What is important is that if you allocate
something you need to do the cleanup yourself. It's unlikely that the
OP will use this program for things other than learning, but he must
know that he has to check for errors and do the cleanup. Let's say he
will write a program that does a lot of memory allocations and he will
consider that it will all be deallocated at exit. What if his program
is supposed to run for a long period of time and call malloc a lot? It
will run out of memory because he's not freeing it and malloc will
eventually fail and he won't know it. If you want to help do it
properly even in small example programs.

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)

 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      03-08-2006
Flash Gordon wrote:
> Richard Heathfield wrote:
>> Flash Gordon said:
>>
>>> People still use DOS

>>
>> Presumably you are referring to MS-DOS.

>
> Or IBM-DOS or Caldera-DOS, or...
>
> In fact, Caldera-DOS seems to be common for bootable BIOS upgrade
> floppies.
>
>>> and that is pretty stupid.

>>
>> Not if it meets their needs better than the alternatives.

>
> I meant that the OS is pretty stupid, not the decision to use it.


Presumably you consider a snow shovel a stupid tool, when you can
use a snowblower with a 10 HP engine instead. I, for one, run
stupid DOS programs every day, many of which are twenty years old.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>


 
Reply With Quote
 
David Holland
Guest
Posts: n/a
 
      03-08-2006
On 2006-03-07, Rod Pemberton <(E-Mail Removed)> wrote:
> Do you _honestly_ think that malloc() will fail to provide 32 bytes? 4Kb?
> 64Kb? on any modern computer, miniframe or mainframe?


As has already been explained, no matter how much storage you have on
your machine, you can still run out.

> Returning resources to an OS, such as deallocation of the memory allocated
> by a program, is a mandatory part of the host OS's "normal program
> termination" and "control ...[being] returned to the host environment."
> Without it, the OS would run out of memory... Since all successful OS's
> where partly developed or influenced heavily by EE's, I doubt that there is
> a 'stupid' OS which doesn't deallocate memory.


No, the OS will only run out of memory if the programs you run on it
fail to release the resources they have allocated and otherwise
generally restore the state of the operating environment.

Many OSes run miscellaneous programs in sandboxes that can be cleaned
up automatically, because the OS's trust model requires it. However,
it's far from universal, nor is the cleanup necessarily complete.

<OT> Even in Unix it's possible to make a mess by failing to clean
certain things up if you've been fiddling with them. </OT>

It is good practice to pick up after yourself, and not go through life
trailing a stream of candy bar wrappers and used tissues behind you.

> Stop being inane.


Indeed.

--
- David A. Holland
(the above address works if unscrambled but isn't checked often)
 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      03-08-2006
CBFalconer wrote:
> Flash Gordon wrote:
>> Richard Heathfield wrote:
>>> Flash Gordon said:
>>>
>>>> People still use DOS
>>> Presumably you are referring to MS-DOS.

>> Or IBM-DOS or Caldera-DOS, or...
>>
>> In fact, Caldera-DOS seems to be common for bootable BIOS upgrade
>> floppies.
>>
>>>> and that is pretty stupid.
>>> Not if it meets their needs better than the alternatives.

>> I meant that the OS is pretty stupid, not the decision to use it.

>
> Presumably you consider a snow shovel a stupid tool, when you can
> use a snowblower with a 10 HP engine instead. I, for one, run
> stupid DOS programs every day, many of which are twenty years old.


This isn't an advocacy group, so I'm going to stop discussing this.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      03-08-2006
Flash Gordon said:

> This isn't an advocacy group, so I'm going to stop discussing this.


Since you know this isn't an advocacy group, it may have been better not to
launch an attack on DOS in the first place.

Incidentally, the term "DOS" was first used a long time before the PC was a
twinkle in IBM's eye. If you'd spent so much on your IBM 360 mainframe that
you were a bit strapped for operating system cash, you went for DOS rather
than OS. (Nothing to do with Tim Patterson's CP/M clone, of course. That
came about 15 years later.)

--
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)
 
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
Josephus Flavius Problem Help Please TheGodfather Java 9 12-01-2007 10:55 PM
help for josephus folks!!! TheGodfather Java 0 11-29-2007 10:30 PM
RING RING RING Dashing through the wind, In a four dog dragged sleigh. Oh the street we go, laughing all the way Mathematician C++ 0 12-24-2006 02:26 PM
Digi-slave L-Ring Ultra II LED Ring Light Jim Hawkins Digital Photography 0 08-16-2005 12:12 PM
Ring ring....ring ring.... Slumpy Computer Support 1 07-06-2003 10:57 PM



Advertisments