Re: init char buffer to null
Re: init char buffer to null
- Subject: Re: init char buffer to null
- From: Tommy Nordgren <email@hidden>
- Date: Wed, 13 Dec 2006 11:54:23 +0100
On 13 dec 2006, at 04.51, Sandro Noel wrote:
Well simply put i'm trying to read bytes from a file, recursively,
so the buffer will be freed right after use...
it is not static because i have no clue on how big the string i
will have to read is,
might be half a file, or just a quarter... and the file is Bytes Data.
unless it's a very bad way of doing it.
The best way to do this, is probably to read in the size of the file
with a stat call,
and then allocate a buffer large enough to fit the entire file
(assuming you are processing text
files and not very large binary files)
Also try reading up on functions to handle virtual memory. It is
possible to map an entire
file into virtual memory space.
i'll try out memset.
thank you much...i read about calloc witch has better
performance... should i use that ?
Sandro
On 12-Dec-06, at 10:44 PM, Chris Suter wrote:
On 13/12/2006, at 2:37 PM, Sandro Noel wrote:
hi, :)
char *buffer;
buffer = malloc(delimiterLocation);
[input getBytes:buffer range:NSMakeRange(index, delimiterLocation)];
// do something
free(buffer);
ok this is simple, my problem lies with buffer initialisation,
i'm not that used to "C" and i was wondering if
Objective-c or Carbon had a specefic function to do such thing...
like a fill function...or something...
the problem is funny, is i read from the file an integer let's
say 10 and at position 3
I had 5 because of old memory, i end up with the number 105 :)
anyways, I know it's a dumb question, and i did try and find in
the docs
but i dont know what i am looking for so, i get a lot of nothing.
memset will initialise memory for you but I don't actually think
you want to do that. You need to post more of the surrounding code.
- Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
40chello.se
This email sent to email@hidden
------
What is a woman that you forsake her, and the hearth fire and the
home acre,
to go with the old grey Widow Maker. --Kipling, harp song of the
Dane women
Tommy Nordgren
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden