By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,495 Members | 1,842 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,495 IT Pros & Developers. It's quick & easy.

How to manage the memory in C?

P: n/a
If the file is very huge, but it is needed to be read in the memory,
how to manage the memory,? Thanks for any comment.

Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"yezi" <ye*****@hotmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
If the file is very huge, but it is needed to be read in the memory,
how to manage the memory,? Thanks for any comment.


Determine the file's size (can be done by opening it
and reading, counting bytes until eof) then allocate
that much memory, and read it in. If the memory allocation
fails, then the whole file won't fit in memory. In that case
you can read what part will fit, then when done with it, read a
different sufficiently small part of the file into that same
memory. Repeat as necessary. (this is known as 'paging', and
is done automatically on systems which feature 'virtual' memory.)

-Mike
Nov 21 '05 #2

P: n/a
Would u mind recommand some books on memory allocation technique by C?
Thanks

Nov 23 '05 #3

P: n/a
"yezi" <ye*****@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Would u mind recommand some books on memory allocation technique by C?
Thanks


I can't assess the quality of any source on this over another,
as I'm no expert in this field; so I'll just advise you to do
what I'd do in your situation:

http://www.google.com/search?hl=en&q...=Google+Search

-Mike
Nov 23 '05 #4

P: n/a
yezi wrote:
If the file is very huge, but it is needed to be read in the memory,
how to manage the memory,? Thanks for any comment.

You need to be more precise. What does 'very huge' mean? How much memory
is available to you? What do you mean by 'managing memory'.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 23 '05 #5

P: n/a
yezi said:
If the file is very huge, but it is needed to be read in the memory,
how to manage the memory,? Thanks for any comment.


Read as little (from the file into memory) as possible but as much as
necessary. If "as much as necessary" is more than you can handle, find a
different algorithm.

For example, if you're right-justifying some text, you need only read one
line into memory at a time.

--
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)
Nov 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.