473,657 Members | 2,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is diff b/w malloc,calloc,r ealloc

What is diff b/w malloc,calloc,r ealloc
could any one explain

Nov 14 '05 #1
6 10689
malloc returns uninitialized memory, calloc initializes the memory to
all bits zero, and realloc is way more flexible than it should be.
realloc can act like malloc or free, or it can resize memory returned
by malloc, calloc, or a previous realloc call, possibly allocating a
new block and invalidating any pointers into the memory.

Nov 14 '05 #2
no*@given.out wrote:
On Wed, 23 Mar 2005 14:41:10 +0100, "Ramasubramania n XR (AS/EAB)"
<ra************ **************@ ericsson.com> wrote:
What is diff b/w malloc,calloc,r ealloc
could any one explain
Pointer = calloc(NumBlock s, BlockSize) ...
Clears and allocates the given number of blocks of a given size. (most
useful for arrays)


Be careful, though: "clears" means "fills with 0-valued bytes", not
necessarily "fills with zero values". In particular, 0x00000000 need not
be the representation of a zero-valued floating point number or of a
null pointer.

Richard
Nov 14 '05 #3
"Ramasubramania n XR (AS/EAB)" wrote:

What is diff b/w malloc,calloc,r ealloc
could any one explain


See the last two references below.

--
Some useful references:
<http://www.ungerhu.com/jxh/clc.welcome.txt >
<http://www.eskimo.com/~scs/C-faq/top.html>
<http://benpfaff.org/writings/clc/off-topic.html>
<http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/> (C99)
<http://www.dinkumware. com/refxc.html> C-library
Nov 14 '05 #4

Ramasubramanian XR (AS/EAB) wrote:
What is diff b/w malloc,calloc,r ealloc
could any one explain


What book are you using that doesn't cover such fundamental memory
management functions?


Brian

Nov 14 '05 #5
Ramasubramanian XR (AS/EAB) wrote on 23/03/05 :
What is diff b/w malloc,calloc,r ealloc
could any one explain


It's all explained in any decent C book or help file.

google : "man malloc" "man realloc" "man calloc"

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

I once asked an expert COBOL programmer, how to
declare local variables in COBOL, the reply was:
"what is a local variable?"

Nov 14 '05 #6
Ramasubramanian XR (AS/EAB) wrote:
What is diff b/w malloc,calloc,r ealloc
could any one explain


Why don't you read the manual or man pages like the rest of us did?
Nov 14 '05 #7

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

Similar topics

18
555
by: Kumar | last post by:
Hi, Can somebody advise me on what is the best alternative for realloc in C++? Is it safe to "realloc"ate memory allocated using new operator ?
37
2550
by: Harsimran | last post by:
Can any one explain what are far pointers and what is the difference between malloc and calloc .Which is better ?
2
286
by: ala | last post by:
I have something near to this: unsigned *p, *a; p = malloc(80*sizeof(unsigned)); a=p; if(p==0) exit(1); <code snip> /******************/ free(p); /******************/
4
2513
by: Lawrie | last post by:
Hi, I am fairly new to C programming and would like to ask a little help with the following problem. I am writing a simple ring buffer, implemented as an array of char *. char* ringbuffer; When I receive a new message (of type char*) I need to make a copy of
19
1829
by: Jerry | last post by:
Hi,all I write a function to copy one memory buffer to anther with dynamic allocationg when the destination is not large enough. The code is below: void DSM_CC::fillBuf(unsigned char** pdstBuf,int* pdstBufBase,int* pdstTolalLen,char* pbufToWrite,int lenToWrite) { unsigned char* tmp; int step = 256;
21
470
by: ramu | last post by:
Hi, Will the memory allocated by malloc and realloc be contiguous? regards
82
31076
by: quiberon2 | last post by:
Hi, Sorry if it might be a stupid question but what should returns malloc(0) ? void *ptr = malloc(0); I am running gcc 3.3.5 and a non-null address is returned. ( in the compiler that I am currently implementing, NULL is returned. Is it wrong ?)
47
537
by: Raman | last post by:
Hi All, As per my understanding, malloc and calloc differs in the way they allocate memory( malloc give a contigous block, But calloc may give Non-contigous block as well). Now consider this program. int main() { char *p;
2
5483
by: rasmidas | last post by:
I have a function, int dmgDocExplodeInception ( sENTITY* Entity, sDOC_SOURCE* DocSource, sUINT Mode ) {
0
8394
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
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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
7327
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
5632
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
4152
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
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.