What is diff b/w malloc,calloc,realloc
could any one explain 6 10667
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. no*@given.out wrote: On Wed, 23 Mar 2005 14:41:10 +0100, "Ramasubramanian XR (AS/EAB)" <ra**************************@ericsson.com> wrote:
What is diff b/w malloc,calloc,realloc could any one explain
Pointer = calloc(NumBlocks, 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
"Ramasubramanian XR (AS/EAB)" wrote: What is diff b/w malloc,calloc,realloc 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
Ramasubramanian XR (AS/EAB) wrote: What is diff b/w malloc,calloc,realloc could any one explain
What book are you using that doesn't cover such fundamental memory
management functions?
Brian
Ramasubramanian XR (AS/EAB) wrote on 23/03/05 : What is diff b/w malloc,calloc,realloc 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?"
Ramasubramanian XR (AS/EAB) wrote: What is diff b/w malloc,calloc,realloc could any one explain
Why don't you read the manual or man pages like the rest of us did? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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 ?
|
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 ?
|
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);
/******************/
|
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;...
|
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**...
|
by: ramu |
last post by:
Hi,
Will the memory allocated by malloc and realloc be contiguous?
regards
|
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...
|
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...
|
by: rasmidas |
last post by:
I have a function,
int dmgDocExplodeInception
(
sENTITY* Entity,
sDOC_SOURCE* DocSource,
sUINT Mode
)
{
|
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...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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: 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...
|
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...
|
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,...
| | |