473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to manage the memory in C?

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
5 2085

"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
Would u mind recommand some books on memory allocation technique by C?
Thanks

Nov 23 '05 #3
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bob Bedford | last post by:
We are 3 persons contacting various potential clients/customers and also potential advertisers for our website. Each person work at home, and it becomes ever difficult to manage our contacts....
5
by: Laser Lu | last post by:
What doese Garbage Collection mean? And what is Managed Code? Any links to relevant articles or resources would be appreciated! -- Best regards, Laser Lu
0
by: Earl Teigrob | last post by:
I am currently using native .net XML classes for managing my little key/value data storage requirements and they work great. I have created a simple class to abstract the XML and manage my...
0
by: Mattia | last post by:
************************************************** Manage image without exhausted memory ************************************************** Hi; I have a big problem. I must create a script that...
11
by: seberino | last post by:
Suppose a C extension locally built an array of PyObject* 's as follows... my_array = malloc(n * sizeof(PyObject*)); for (i = 0; i < n; i++) { my_array = PyList_New(0); } Q1: Must I do a...
2
by: Giuseppe | last post by:
Hi everybody, this is my first post in this group since it is from little time that I have begun to learn c++. My problem is to post a web form using the libcurl library. The form is at this...
0
by: Arthernan | last post by:
I have an Active-X control provided by a vendor that will inadvertenly crash while processing. The good part is that I do have a way to save information routinely as it is processing in the event...
4
by: themadjester | last post by:
So, I have not really used vista, I mean I have used other peoples vista enough to tell that I don't feel that "OMG I NEED THIS" and I have used word 2007 which left me less than impressed and gave...
10
by: DeveloperDave | last post by:
Hi, I am trying to improve some code that I currently have. I have a simple class called RequestMessage e.g. class RequestMessage { public: RequestMessage();
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.