Re: similar Perl data structure?
- From: Ian Collins <ian-news@xxxxxxxxxxx>
- Date: Mon, 20 Apr 2009 19:24:10 +1200
jacob navia wrote:
Ian Collins wrote:jacob navia wrote:The problem with C is not the language itself.
In this example, part of the problem is the language.
One big difference between the two versions is the user of your C function has to remember to free all the allocated memory (which the example fails to do). The C++ version takes care of this though those (in your opinion) horrible destructors.
Not if you use lcc-win and use the GC.
Does that automatically close files for you, or release locks? Memory is just one of the resources a programme has to manage.
But there is an important point in your objection. Either a function
to free the memory should be supplied or a SINGLE call to free
should be required. I am rewriting the program to use a different
algorithm. Instead of reading line by line I read it in a single
read, then count the lines, and allocate a single buffer with
all the pointers AND the data.
That should be more efficient and gives an easier interface.
In standard C? Probably not. Using platform specifics (file mapping) probably yes.
But as you see if you use the GC, you do not need destructors
in this case!
You still have to close the file.
--
Ian Collins
.
- Follow-Ups:
- Re: similar Perl data structure?
- From: jacob navia
- Re: similar Perl data structure?
- References:
- similar Perl data structure?
- From: ela
- Re: similar Perl data structure?
- From: jacob navia
- Re: similar Perl data structure?
- From: Ian Collins
- Re: similar Perl data structure?
- From: jacob navia
- Re: similar Perl data structure?
- From: Ian Collins
- Re: similar Perl data structure?
- From: jacob navia
- Re: similar Perl data structure?
- From: Ian Collins
- Re: similar Perl data structure?
- From: jacob navia
- Re: similar Perl data structure?
- From: Ian Collins
- Re: similar Perl data structure?
- From: jacob navia
- similar Perl data structure?
- Prev by Date: Re: Value of Un-initialized Stack Variable in OSX
- Next by Date: Re: Check whether an argument in command line is a number
- Previous by thread: Re: similar Perl data structure?
- Next by thread: Re: similar Perl data structure?
- Index(es):
Relevant Pages
|