RE: again a newbee question

  • From: "Sina Bahram" <sbahram@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 13 Apr 2011 23:40:40 -0400

Let's go through, line by line:

Ty: You are advocating using global functions to free up something that should 
be OOP and probably is in a carefully well-designed
app.

Memory management, by its definition has global components to it. this is true 
in even managed contexts in which a garbage collector
runs globally.

And also, I'm not saying register every little piece against atexit, but rather 
use the built in features of the language so you
register the big boys, and cascade down from there; furthermore, it's 
completely OO, because the registration process can be done in
an OO way via a myriad of means.

Ty: So shall we all just use global pointers to resources so that the atexit 
handlers can delete them?

No

Ty: Just calling exit and leaving the OS to delete things kind of kills the 
whole portability idea.

Actually, it kills the idea of good design, but really has no effect on 
portability, if you want to get technical about semantics.

Ty: Sure Windows and Linux give you back the memory you've claimed, but there 
are resources (direct 3d, as Chris already gave an
example of) that won't get freed, nor should they.

I disagree. I do think that they, quote, should, unquote, and this is the 
entire purpose behind the last decade of language and
programming environment design; however, I explained above how external 
resources would be handled.

Ty: Also if you call out to a shared library that is mapped into two processes 
and the library creates memory, without you free the
memory that your program requires, the memory is going to stay allocated until 
the library gets unloaded.

First of all, why are you mapping your library in process? Other than some 
specific use cases such as how jaws runs pieces of itself
in process in IE for minimization of dom request delays via MSAA, I can't 
imagine this is a good idea. You want to talk about
destroying any chance of good design or even the thought of portability ... 
that's what to do right there.

Second of all, you are repeatedly conflating library and program. Why would I 
need to free memory that my program requires in a
discussion about a library which is mapped into it?

I'd recommend actually learning about how modern operating systems perform 
paging, memory management, and scheduling. You have
several of these concepts confused.

Ty: I think confused is the right word, yes.

Yes, I agree, confused is definitely the right word.

Take care,
Sina

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx 
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Littlefield, Tyler
Sent: Wednesday, April 13, 2011 11:27 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: Re: again a newbee question

Sina:
You are advocating using global functions to free up something that 
should be OOP and probably is in a carefully well-designed app. So shall 
we all just use global pointers to resources so that the atexit handlers 
can delete them? Just calling exit and leaving the OS to delete things 
kind of kills the whole portability idea. Sure Windows and Linux give 
you back the memory you've claimed, but there are resources (direct 3d, 
as Chris already gave an example of) that won't get freed, nor should 
they. Also if you call out to a shared library that is mapped into two 
processes and the library creates memory, without you free the memory 
that your program requires, the memory is going to stay allocated until 
the library gets unloaded. I think confused is the right word, yes.
On 4/13/2011 9:16 PM, Sina Bahram wrote:
> What are you talking about!
>
> Exit is part of an API to do exactly that. You can register functions, or 
> callbacks, that even get called before it exits the
> program. Furthermore, it cleanly ends streams so that data isn't lost, and it 
> also handles temporary file handles.
>
> I'm sorry, but do you teach posix compliance at all, or anything?
>
> Because, I'm so confused as to how you don't know this about exit.
>
> Are you familiar with the atexit function, and how it is used to register 
> callback events?
>
> As for C++. If you have properly coded cascading destructors fed by a simple 
> broadcast message or other form of notification, then
> what's the problem with calling exit after that runs?
>
> Of course you would clean up your external resources before calling exit, but 
> you can use the exit interface to do even this. In
> fact, that's encouraged. So, yes, i am saying they could easily use exit and 
> not leave one byte of memory unfreed, and do so
> cleanly.
>
> Take care,
> Sina
>
> -----Original Message-----
> From: programmingblind-bounce@xxxxxxxxxxxxx 
> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Christopher Coale
> Sent: Wednesday, April 13, 2011 11:00 PM
> To: programmingblind@xxxxxxxxxxxxx
> Subject: Re: again a newbee question
>
> First of all, what you explained to me that it does has nothing to do
> with control structure. C and C++ are structured languages, so when
> people unnecessarily use things that break the structure (such as goto),
> I am not too fond of it.
>
> So let me get this straight.. you are advocating that a programmer
> simply call exit() instead of using the proper API to release resources
> they allocated, prior to quitting the program?
>
> On 4/13/2011 7:41 PM, Sina Bahram wrote:
>> I don't understand what that means.
>>
>> Totally destroys what structure?
>>
>> It's an exit ... of course it destroys everything.
>>
>> Furthermore, exit is an extremely clean way of exiting a program. It's a 
>> million times better than return 0.
>>
>> It actually calls, in reverse order of course, all functions which 
>> registered via atexit. It also closes streams, not only IO
ones
>> for that matter, and it gets rid of/cleans temporary files.
>>
>> Quite puzzled ...
>>
>> Take care,
>> Sina
>>
>> -----Original Message-----
>> From: programmingblind-bounce@xxxxxxxxxxxxx 
>> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Christopher Coale
>> Sent: Wednesday, April 13, 2011 9:38 PM
>> To: programmingblind@xxxxxxxxxxxxx
>> Subject: Re: again a newbee question
>>
>> Alright, I just wanted to force you to clarify, so you don't give Ashish
>> the wrongi dea. ;) I grade C++ programming assignments, and I see new
>> C++ programmers using the exit function simply because it's convenient,
>> but it totally destroys the structure.
>>
>> On 4/13/2011 6:35 PM, Ken Perry wrote:
>>> Well I was using exit as a concept more than a method since depending on the
>>> gui you code in there are things like finish, exit, delete and all kinds of
>>> way to make a program die.
>>>
>>> Ken
>>>
>>> -----Original Message-----
>>> From: programmingblind-bounce@xxxxxxxxxxxxx
>>> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Christopher
>>> Coale
>>> Sent: Wednesday, April 13, 2011 9:28 PM
>>> To: programmingblind@xxxxxxxxxxxxx
>>> Subject: Re: again a newbee question
>>>
>>> Careful with saying "until you call exit." You don't want to give the
>>> impression that the exit() function is okay in a structured program, do
>>> we? ;)
>>>
>>> On 4/13/2011 6:25 PM, Ken Perry wrote:
>>>> Nod you will not need things like scanf and getch and things of the like
>>>> when you get into serious coding because you will be probably building
>>>> windows apps of some kind and the window will remain open till you call
>>>> exit.  This is just while you're learning so feel free to use scanf,
>>> getch,
>>>> getchar, or any of the things like read to just hold the program till your
>>>> ready to close.
>>>>
>>>> Ken
>>>>
>>>> -----Original Message-----
>>>> From: programmingblind-bounce@xxxxxxxxxxxxx
>>>> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of ashish rohtagi
>>>> Sent: Wednesday, April 13, 2011 9:05 PM
>>>> To: programmingblind@xxxxxxxxxxxxx
>>>> Subject: Re: again a newbee question
>>>>
>>>> sorry, I corrected the mistake about printf and scanf. thanks for the
>>>> advice. take care, regards. ashish
>>>>
>>>> On 4/14/11, Littlefield, Tyler<tyler@xxxxxxxxxxxxx>     wrote:
>>>>> I'm sorry, getch should be getchar. Also: it's fairly bad coding style
>>>>> to put a printf on the same line as a scanf. Unless you have good
>>>>> reason, try to keep your code separated. It makes it easier to read and
>>>>> people don't miss things quite as easily.
>>>>> On 4/13/2011 6:50 PM, ashish rohtagi wrote:
>>>>>> like this?? #include<stdio.h>
>>>>>>
>>>>>> int main()
>>>>>> {
>>>>>> char me[20];
>>>>>>
>>>>>>
>>>>>>
>>>>>> printf("What is your name?"); scanf("%s",&me);
>>>>>> printf("Darn glad to meet you, %s!\n",me);
>>>>>>
>>>>>> scanf("s%",&me);
>>>>>>
>>>>>> return(0);
>>>>>> } but result is still the same. can I use getch fungtion? if yes
>>>>>> please tell me how to use it . take care, regards.
>>>>>>
>>>>>>
>>>>>> On 4/14/11, Jared Wright<wright.jaredm@xxxxxxxxx>      wrote:
>>>>>>> It goes right between the last printf statement and the return
>>>>>>> statement. It's job is to hold the program open at the end, so it
>>> should
>>>>>>> be the last statement before return, which ends the program.
>>>>>>> On 4/13/2011 12:09 PM, ashish rohtagi wrote:
>>>>>>>> hi Tyler, thanks for your suggestion, but I am unable to understand
>>>>>>>> where to put second scanf. will you just once show me? take care,
>>>>>>>> regards. ashish
>>>>>>>>
>>>>>>>> On 4/13/11, Littlefield, Tyler<tyler@xxxxxxxxxxxxx>       wrote:
>>>>>>>>> Like ken said, use scanf to catch it before the window closes, or run
>>>>>>>>> it
>>>>>>>>> in a command line. Here's what's happening:
>>>>>>>>> You open the process, and the first scanf call blocks; that is to
>>> say,
>>>>>>>>> it will not process anything, it is simply waiting for the user to
>>>>>>>>> input
>>>>>>>>> something. But after it's done printing, there is no reason why it
>>>>>>>>> should stay open because you don't tell it to. So run from the
>>> command
>>>>>>>>> prompt, use getch() to let you hit enter before it closes or use
>>>>>>>>> another
>>>>>>>>> scanf.
>>>>>>>>> On 4/13/2011 9:32 AM, ashish rohtagi wrote:
>>>>>>>>>> friends, thanks for all the  encouragement. here is my problem, I
>>>> want
>>>>>>>>>> to use scanf fungtion. in input and output but as soon as I give my
>>>>>>>>>> input and press enter the window disappears. it does not give output
>>>>>>>>>> based on my input. here is the code. #include<stdio.h>
>>>>>>>>>>
>>>>>>>>>> int main()
>>>>>>>>>> {
>>>>>>>>>> char me[20];
>>>>>>>>>>
>>>>>>>>>> printf("What is your name?"); scanf("%s",&me);
>>>>>>>>>> printf("Glad to meet you, %s!\n",me); return(0);
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On 4/13/11, Littlefield, Tyler<tyler@xxxxxxxxxxxxx>        wrote:
>>>>>>>>>>> O. oops. In my defense, I haven't found coffee. :)
>>>>>>>>>>> On 4/13/2011 7:46 AM, Jared Wright wrote:
>>>>>>>>>>>> It's there, just on the same line as the printf statement.
>>>>>>>>>>>> On 4/13/2011 9:35 AM, Littlefield, Tyler wrote:
>>>>>>>>>>>>> good job on using int main, just don't forget a return 0; when
>>> you
>>>>>>>>>>>>> are
>>>>>>>>>>>>> done. between the printf and the closing brace.
>>>>>>>>>>>>> On 4/13/2011 6:36 AM, ashish rohtagi wrote:
>>>>>>>>>>>>>> here is my code it compiles correctly but text just shows on the
>>>>>>>>>>>>>> screen for 1 second, I want it to stay. #include<stdio.h>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> int main()
>>>>>>>>>>>>>> {
>>>>>>>>>>>>>> printf("I will learn programming!\n"); return(0);
>>>>>>>>>>>>>> }
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On 4/13/11, DaShiell, Jude T. CIV NAVAIR 1490, 1, 26
>>>>>>>>>>>>>> <jude.dashiell@xxxxxxxx>        wrote:
>>>>>>>>>>>>>>> You didn't put your printf statement in your message, but let
>>> me
>>>>>>>>>>>>>>> make a
>>>>>>>>>>>>>>> guess. You didn't put a (\n) in before the closing quote mark
>>> so
>>>>>>>>>>>>>>> you
>>>>>>>>>>>>>>> just put text on the screen without a line ending. That could
>>> be
>>>>>>>>>>>>>>> one
>>>>>>>>>>>>>>> contributing factor. Another might be you didn't put an
>>> #include
>>>>>>>>>>>>>>> <stdio.h>        statement in at the top of your program and 
>>>>>>>>>>>>>>> maybe
>>>>>>>>>>>>>>> used
>>>>>>>>>>>>>>> #include<conio.h>. If that's the case, don't use printf with
>>>>>>>>>>>>>>> conio.h
>>>>>>>>>>>>>>> unless you also include stdio.h. For conio.h, cprintf is the
>>>>>>>>>>>>>>> function
>>>>>>>>>>>>>>> you want. Hope this helps.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> -----Original Message-----
>>>>>>>>>>>>>>> From: programmingblind-bounce@xxxxxxxxxxxxx
>>>>>>>>>>>>>>> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of
>>>>>>>>>>>>>>> ashish
>>>>>>>>>>>>>>> rohtagi
>>>>>>>>>>>>>>> Sent: Wednesday, April 13, 2011 8:04
>>>>>>>>>>>>>>> To: programmingblind@xxxxxxxxxxxxx
>>>>>>>>>>>>>>> Cc: punitdiwan@xxxxxxxxx
>>>>>>>>>>>>>>> Subject: again a newbee question
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> friends, sorry here I am with another foolish question, sorry
>>>> but
>>>>>>>>>>>>>>> here
>>>>>>>>>>>>>>> is no one to teach and I am learning myself. when I print any
>>>>>>>>>>>>>>> text
>>>>>>>>>>>>>>> on
>>>>>>>>>>>>>>> screen using printf it quickly disappears. what should I do
>>> that
>>>>>>>>>>>>>>> it
>>>>>>>>>>>>>>> should stay? take care, regards. ashish
>>>>>>>>>>>>>>> __________
>>>>>>>>>>>>>>> View the list's information and change your settings at
>>>>>>>>>>>>>>> //www.freelists.org/list/programmingblind
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> __________
>>>>>>>>>>>>>>> View the list's information and change your settings at
>>>>>>>>>>>>>>> //www.freelists.org/list/programmingblind
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> __________
>>>>>>>>>>>>>> View the list's information and change your settings at
>>>>>>>>>>>>>> //www.freelists.org/list/programmingblind
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>> __________
>>>>>>>>>>>> View the list's information and change your settings at
>>>>>>>>>>>> //www.freelists.org/list/programmingblind
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>>
>>>>>>>>>>> Thanks,
>>>>>>>>>>> Ty
>>>>>>>>>>>
>>>>>>>>>>> __________
>>>>>>>>>>> View the list's information and change your settings at
>>>>>>>>>>> //www.freelists.org/list/programmingblind
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>> __________
>>>>>>>>>> View the list's information and change your settings at
>>>>>>>>>> //www.freelists.org/list/programmingblind
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>> --
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>> Ty
>>>>>>>>>
>>>>>>>>> __________
>>>>>>>>> View the list's information and change your settings at
>>>>>>>>> //www.freelists.org/list/programmingblind
>>>>>>>>>
>>>>>>>>>
>>>>>>>> __________
>>>>>>>> View the list's information and change your settings at
>>>>>>>> //www.freelists.org/list/programmingblind
>>>>>>>>
>>>>>>> __________
>>>>>>> View the list's information and change your settings at
>>>>>>> //www.freelists.org/list/programmingblind
>>>>>>>
>>>>>>>
>>>>>> __________
>>>>>> View the list's information and change your settings at
>>>>>> //www.freelists.org/list/programmingblind
>>>>>>
>>>>>>
>>>>> --
>>>>>
>>>>> Thanks,
>>>>> Ty
>>>>>
>>>>> __________
>>>>> View the list's information and change your settings at
>>>>> //www.freelists.org/list/programmingblind
>>>>>
>>>>>
>>>> __________
>>>> View the list's information and change your settings at
>>>> //www.freelists.org/list/programmingblind
>>>>
>>>> __________
>>>> View the list's information and change your settings at
>>>> //www.freelists.org/list/programmingblind
>>>>
>>> __________
>>> View the list's information and change your settings at
>>> //www.freelists.org/list/programmingblind
>>>
>>> __________
>>> View the list's information and change your settings at
>>> //www.freelists.org/list/programmingblind
>>>
>> __________
>> View the list's information and change your settings at
>> //www.freelists.org/list/programmingblind
>>
>> __________
>> View the list's information and change your settings at
>> //www.freelists.org/list/programmingblind
>>
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
>


-- 

Thanks,
Ty

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: