LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-18-2004, 01:34 AM   #1
eshwar_ind
Member
 
Registered: Feb 2004
Location: Bangalore
Distribution: Redhat
Posts: 144

Rep: Reputation: 15
about malloc


Whats the maximum memory that can allocated using malloc ( is it 28KB on linux)?
Whats the difference between huge and far pointers ?
Please reply me
bye,
Eshwar
 
Old 02-18-2004, 01:49 AM   #2
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
you can allocate memory as long as you have free ram. with 32bit addresses, you can address up to 4gigs of memory; you're only limited by system ram unless you have a HUGE amount of ram, in which case you'd probably be on a machine with 64bit addressing. long and far pointers have somethign to do with segments, and are only relevant with flat addressing mode. with virtual addressing we dont have to worry about near/far pointers. someone else may want to explain that last part better tho
 
Old 02-18-2004, 01:53 AM   #3
eshwar_ind
Member
 
Registered: Feb 2004
Location: Bangalore
Distribution: Redhat
Posts: 144

Original Poster
Rep: Reputation: 15
thanks infamous .
One more question...
How do i allocate a huge or far memory using malloc?
 
Old 02-18-2004, 01:54 AM   #4
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
well, i dont think that you worry about near/far pointers like i said. what is it you are trying to do?
 
Old 02-18-2004, 02:00 AM   #5
eshwar_ind
Member
 
Registered: Feb 2004
Location: Bangalore
Distribution: Redhat
Posts: 144

Original Poster
Rep: Reputation: 15
These are interview questions and my doubts too?
is it possibe to allocate get a far memory piece using malloc?
As you said whats the routine we use to get far memory piece in flat address space?
I think C has the ability to give this thing regard less of whether it is flat or two modes or three modes. What do u say?
 
Old 02-18-2004, 07:35 AM   #6
cjcuk
Member
 
Registered: Dec 2003
Distribution: Openwall, ~LFS
Posts: 128

Rep: Reputation: 15
If you are allocating a large area of memory, you may be better off using mmap(2) rather than malloc(3). You can use anonymous mmaps to gain a memory mapping with no file to back it up.
 
Old 02-18-2004, 07:48 AM   #7
PSIplus
Member
 
Registered: Feb 2004
Location: Vienna/Austria
Distribution: Debian Unstable
Posts: 36

Rep: Reputation: 15
Yes, including files via mmap is a nice solution, but you can use a conbined block-file structure like many editors do it with large files:
malloc a block buffer using a struct - if you require only require a "visible area" for example like the text you currently see in the editor) plus some buffer for faster scrolling or so, define a memory area for this.
use mmap to map one or more tempfiles into your application carrying the "unseen" part of the memory. It is also possible to use fread and fwrite, they are a good solution because of the buffering and block handling.
 
Old 02-18-2004, 12:15 PM   #8
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
eshwar << i dont know enuf about that to give you an answer suitable for an interview
two above << uhh, read the first post. we're not talkin about mmap.
 
Old 02-18-2004, 01:19 PM   #9
cjcuk
Member
 
Registered: Dec 2003
Distribution: Openwall, ~LFS
Posts: 128

Rep: Reputation: 15
infamous41md: I realize the thread is about malloc, I was merely stating if he is using larger areas of memory he may wish to use mmap instead.

eschwar_ind: as far as I know, standard implementations of malloc are only allocating using brk(2) to grow the heap of the process. Therefore, it will only return memory that is valid within the heap. Although some simple mallocs on machines without heaps just use continuous mmapping, I do not think that most implementations will fall back to mmapping elsewhere in the virtual address range - I think they will just set ENOMEM and be done with it. From within a process you are only looking at a virtual memory address range anyway. However, despite hopefully clarifying that for you eschwar_ind, I am still unsure as to exactly what you want to know.
 
Old 02-18-2004, 02:21 PM   #10
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
The way the question is worded I would say it had a 16 bit Windows slant - i.e., Win9x Os applications. MSVC++ v 6.0 allows FAR, but I don't think it does anything with it, like it does with register.

One other point. Generally managers interview new prospects. Most managers, if they can code at all, have not done so for years. You may be seeing something like that in the question.

If you get a technical interview as well, they will ask about FAR only if it's relevant (like Win 3.1 development under MSVC++ v4.0 and older). If it is relevant the company you are interviewing with is doing legacy app maintenance. No brand new apps come out for 3.1, 95, MS_DOS etc,
anymore. The market will not support it.
 
Old 02-18-2004, 02:25 PM   #11
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
PS: the limit to memory was machine dependent, up to 384K, when FAR was actually needed in code for MS products. Machines had from 32K to 384K with EMS. Addressing EMS meant using FAR pointers.

The huge memory model was mostly found in Turbo C up to v3.5, I think.
Turbo C code ran under MS-DOS, and still runs in DOS windows under Windows.
 
Old 02-18-2004, 04:41 PM   #12
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
http://atrevida.comprenica.com/atrtut04.html
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
malloc eagle683 Programming 6 05-22-2005 03:40 PM
problem using malloc in C huble Programming 10 03-27-2005 01:45 AM
malloc in c programming saiz66 Programming 18 10-04-2004 03:00 PM
malloc() vijeesh_ep Programming 4 08-25-2004 04:50 PM
malloc debugger legolas_t Programming 3 07-04-2004 02:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration