473,698 Members | 2,883 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

far pointers

Can any one explain what are far pointers and what is the difference
between malloc and calloc .Which is better ?
Nov 14 '05 #1
37 2568
Harsimran <sa************ @yahoo.co.in> scribbled the following:
Can any one explain what are far pointers and what is the difference
between malloc and calloc .Which is better ?


Far pointers are not an ISO standard C concept and are thus off-topic
here. There are two differences between malloc and calloc:
1) malloc excepts one parameter, calloc excepts two. The size that
calloc allocates is the parameters multiplied together.
2) calloc automatically zeroes the allocated memory, malloc does not.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"How can we possibly use sex to get what we want? Sex IS what we want."
- Dr. Frasier Crane
Nov 14 '05 #2
In article <news:b8******* *************** ****@posting.go ogle.com>
Harsimran <sa************ @yahoo.co.in> wrote:
Can any one explain what are far pointers ...
There are no such things. (See the comp.lang.c FAQ, question 19.40d.)
and what is the difference between malloc and calloc .Which is better ?


Which is better, chocolate or strawberry; coconut or soy sauce;
a hammer or a wrench?

A call of the form malloc(n) returns either NULL (failure) or a
pointer to the first of n contiguous bytes. A call of the form
calloc(nitems, size) returns either NULL (failure) or a pointer
to the first of nitems*size contiguous bytes, after also calling
memset() to set all those bytes to '\0'.

If you need bytes pre-set to '\0' you can use calloc(); if you just
need bytes, use malloc().
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #3
"Chris Torek" <no****@torek.n et> wrote in message
news:cf******** @news3.newsguy. com...
In article <news:b8******* *************** ****@posting.go ogle.com>
Harsimran <sa************ @yahoo.co.in> wrote:
and what is the difference between malloc and calloc .Which is better ?
Which is better, chocolate or strawberry; coconut or soy sauce;
a hammer or a wrench?


I'd rather be hammered than wrenched...

Coconut sauce???
If you need bytes pre-set to '\0' you can use calloc(); if you just
need bytes, use malloc().


Right, if you are going to malloc() some space then set it all to zero, you
might as well just use calloc(). This can sometimes be the "coward's way
out". If you don't think you can handle using your memory properly, and have
errors in calculating addresses where you are "one off", it's nice to have
the safety net of a zeroed out chunk of memory - no random values. For
instance, when storing strings in malloc'ed memory, if you forget the
terminating '\0', the calloc assures it is already there. So what I'm saying
is calloc() can hide subtle bugs and overruns, so the program may work, but
still have bugs.
I sometimes used calloc in beginning development, to get going, and switched
back to malloc to find bugs and overruns for the real code. But that was a
long time ago - now I want to know right away.

Can anyone come up with a good reason to zero out "raw" memory before you've
even used it? ...maybe to make sure there are zeroes in the empty
byte-aligned null space???

--
Mabden
p.s. I've been wrong before...
Nov 14 '05 #4
Mabden <mabden@sbc_glo bal.net> wrote:
Can anyone come up with a good reason to zero out "raw" memory before you've
even used it? ...maybe to make sure there are zeroes in the empty
byte-aligned null space???


Needing an array of ints (or long ints) with all elements initialized
to 0 is more or less the only time I use calloc().

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Nov 14 '05 #5
Harsimran wrote:

Can any one explain what are far pointers
It may have something to do with Borland.
and what is the difference
between malloc and calloc .Which is better ?


I use calloc when I want to allocate memory filled
with zero value bytes. That's what calloc is for.

--
pete
Nov 14 '05 #6
pete wrote on 12/08/04 :
Can any one explain what are far pointers


It may have something to do with Borland.


Not only. It has somehing to do with x86 arch in real mode.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html

"C is a sharp tool"

Nov 14 '05 #7
Je***********@p hysik.fu-berlin.de wrote:
Mabden <mabden@sbc_glo bal.net> wrote:
Can anyone come up with a good reason to zero out "raw" memory
before you've even used it? ...maybe to make sure there are
zeroes in the empty byte-aligned null space???


Needing an array of ints (or long ints) with all elements
initialized to 0 is more or less the only time I use calloc().


While that may work for you, it is not guaranteed by the standard.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 14 '05 #8
Joona I Palaste wrote:
Harsimran <sa************ @yahoo.co.in> scribbled the following:
Can any one explain what are far pointers and what is the difference
between malloc and calloc .Which is better ?
Far pointers are not an ISO standard C concept and are thus off-topic
here. There are two differences between malloc and calloc:
1) malloc excepts one parameter, calloc excepts two. The size that

^^^^^^^ ^^^^^^^
accepts :-)
calloc allocates is the parameters multiplied together.
2) calloc automatically zeroes the allocated memory, malloc does not.


--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 14 '05 #9

On Thu, 12 Aug 2004, CBFalconer wrote:

Je***********@p hysik.fu-berlin.de wrote:
Needing an array of ints (or long ints) with all elements
initialized to 0 is more or less the only time I use calloc().


While that may work for you, it is not guaranteed by the standard.


Amplification (sorry!;) : memsetting an 'int' to zero is not
guaranteed by the Standard to set the actual /value/ of that 'int'
to the integer zero. (But I think there's some debate about that;
I forget the details.) So what Jens is suggesting doesn't work.

However, unsigned types are guaranteed to have pure binary
representations , which means that memsetting an 'unsigned int' to
zero /will/ set its value to the unsigned integer zero! Ditto
'unsigned char', 'unsigned long', et cetera. (And I think ditto
the new C99 fixed-width types: 'int32_t' and 'int_least8_t' and
friends.)

I often use 'calloc' in image processing; for example, to get
a grayscale image of size w*h initialized to black, I'll write

unsigned char *im = calloc(w*h, 1);

So 'calloc' does have its uses; they're just rare.

-Arthur
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
3399
by: Susan Baker | last post by:
Hi, I'm just reading about smart pointers.. I have some existing C code that I would like to provide wrapper classes for. Specifically, I would like to provide wrappers for two stucts defined as ff: typedef struct { float *data ; int count ;
3
3444
by: ozbear | last post by:
This is probably an obvious question. I know that pointer comparisons are only defined if the two pointers point somewhere "into" the storage allocated to the same object, or if they are NULL, or one-past the end of the object as long as it isn't dereferenced. I use "object" in the standard 'C' sense. Is there some special dispensation given to comparing two pointers
9
5061
by: Mikhail Teterin | last post by:
Hello! I'd like to have a variable of a pointer-to-function type. The two possible values are of type (*)(FILE *) and (*)(void *). For example: getter = straight ? fgetc : gzgetc; nextchar = getter(file); What type should I give to `getter' so that the compiler does not issue
12
4083
by: Lance | last post by:
VB.NET (v2003) does not support pointers, right? Assuming that this is true, are there any plans to support pointers in the future? Forgive my ignorance, but if C# supports pointers and C# and VB.NET get compiled into the same code, then I don't understand why VB.NET can't support pointers Thanks for any info Lance
14
2829
by: Alf P. Steinbach | last post by:
Not yet perfect, but: http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01.pdf http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01_examples.zip To access the table of contents, use the "Bookmarks" tab in Adobe Acrobat. Comments, corrections, praise, nits, etc., are still welcome!
92
5083
by: Jim Langston | last post by:
Someone made the statement in a newsgroup that most C++ programmers use smart pointers. His actual phrase was "most of us" but I really don't think that most C++ programmers use smart pointers, but I just don't know. I don't like them because I don't trust them. I use new and delete on pure pointers instead. Do you use smart pointers?
4
3509
by: Josefo | last post by:
Hello, is someone so kind to tell me why I am getting the following errors ? vector_static_function.c:20: error: expected constructor, destructor, or type conversion before '.' token vector_static_function.c:21: error: expected constructor, destructor, or type conversion before '.' token
25
13030
by: J Caesar | last post by:
In C you can compare two pointers, p<q, as long as they come from the same array or the same malloc()ated block. Otherwise you can't. What I'd like to do is write a function int comparable(void *p, void *q) that will take any two pointers and decide whether they can be compared or not. I really can't think how to do this - any suggestions?
54
11977
by: Boris | last post by:
I had a 3 hours meeting today with some fellow programmers that are partly not convinced about using smart pointers in C++. Their main concern is a possible performance impact. I've been explaining the advantages of smart pointers endlessly (which are currently used in all our C++ software; we use the Boost smart pointers) as I'm seriously concerned that there is a shift to raw pointers. We are not developing system software but rather...
2
2983
by: StevenChiasson | last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller. This is more or less, your standard dynamic address book program. Adding, and listing work just fine. However, deleting, editing and viewing relies on member function retAddress. This function returns an array of pointers that are pointing to created objects. In action, all it...
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8610
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7740
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.