01-04-2009
You are right. I check the code and finally find that the error is from an assignment. but it is still strange.
list[size-2]->left = list[size-1];
the result is: list[size-2] = list[size-1];
As said before, correct before list[8] and wrong from list[9], ->left seems not to exist
10 More Discussions You Might Find Interesting
1. Programming
Hi,
I'm trying to learn how to manage memory when I have to deal with lots of data.
Basically I'm indexing a huge file (5GB, but it can be bigger), by creating tables that
holds offset <-> startOfSomeData information. Currently I'm mapping the whole file at
once (yep!) but of course the... (1 Reply)
Discussion started by: emitrax
1 Replies
2. Programming
Actually for a process to run it needs text, stack , heap and data segments. All these find a place in the physical memory.
Out of these 4 only heap does exist after the termination of the process that created it. I want to know the exact reason why this happens. Also why the other process need to... (20 Replies)
Discussion started by: karthiktceit
20 Replies
3. Programming
there seems not to be error in this segment. In some computers, it can work well. But in others, it will give a failure.
why it ocurrs and how to deal with it?
in a function:
if( *ver == NULL ) {
*ver = (vertex *) malloc(sizeof(vertex)); //this line
... (17 Replies)
Discussion started by: cdbug
17 Replies
4. Programming
Hi to all,
Recently i am testing an equipment that runs in i586 fedora linux. I have to test mmap function. For that i determined to fill the memory and run the required application to check whether it throws any mmap error regarding low resources.
This is the line that does the allocation. ... (3 Replies)
Discussion started by: frozensmilz
3 Replies
5. Programming
In a 'C' program,when I am trying to allocate memory with the help of malloc () function, it is allocating the memory up to a certain limit for e.g. in my case, it is 670 MB (approx). malloc() returns NULL if I allocate more than this amount of memory.When I tried
to allocate memory in chunks of... (1 Reply)
Discussion started by: vipinsachan
1 Replies
6. Programming
Hi All,
I have a simple code which does some computation by matching string patterns.
In brief:
1. The code reads .dat and .txt files.
2. .dat files are huge text files and .txt files contain some important words.
3. I am just doing strstr to find the patterns.
4. The function returns the... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies
7. Programming
*** glibc detected *** ./a.out: malloc(): memory corruption (fast):
Posted A minute ago
M trying to make multiway tree and dont know what happend when this part of code get executed:
01void ins(NODE *ptr)
02{
03 //working
04 if(ptr!=NULL)
05 {
06 SNODE *var=NULL;
07 var=(SNODE... (3 Replies)
Discussion started by: exgenome
3 Replies
8. Programming
I am using libxml2 library for XMl parsing and libxml++ is C++ wrapper over that. So I am using API of libxml++. I am creating my class and composing instance xmlpp::Node *pNode in that. my class also have funciton prepareXPathQuery() which creates query string and have other fucntion... (2 Replies)
Discussion started by: sharadwagh
2 Replies
9. Programming
Hi Friends,
while executing the below code, am getting *** glibc detected *** ./ok: malloc(): memory corruption (fast) error, please suggest how to solve this issue.
#include <stdio.h>
#include <string.h>
#include <sqlca.h>
#include <alloca.h>
/* Define constants for VARCHAR... (2 Replies)
Discussion started by: mpjobsrch
2 Replies
10. Programming
I am facing a problem of memory corruption. The loop runs for the first time but does not go through the second time. What could be the problem?
for(int z=0;z<2;z++)
{
fp=fopen("poly.dat","r");
/*do something which reads this file into a 2D array*/
fclose(fp);
... (10 Replies)
Discussion started by: dare
10 Replies
LEARN ABOUT NETBSD
realloc
MALLOC(3) BSD Library Functions Manual MALLOC(3)
NAME
malloc, calloc, realloc, free -- general purpose memory allocation functions
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <stdlib.h>
void *
malloc(size_t size);
void *
calloc(size_t number, size_t size);
void *
realloc(void *ptr, size_t size);
void
free(void *ptr);
DESCRIPTION
The malloc() function allocates size bytes of uninitialized memory. The allocated space is suitably aligned (after possible pointer coer-
cion) for storage of any type of object.
The calloc() function allocates space for number objects, each size bytes in length. The result is identical to calling malloc() with an
argument of ``number * size'', with the exception that the allocated memory is explicitly initialized to zero bytes.
The realloc() function changes the size of the previously allocated memory referenced by ptr to size bytes. The contents of the memory are
unchanged up to the lesser of the new and old sizes. If the new size is larger, the value of the newly allocated portion of the memory is
undefined. Upon success, the memory referenced by ptr is freed and a pointer to the newly allocated memory is returned. Note that realloc()
may move the memory allocation, resulting in a different return value than ptr. If ptr is NULL, the realloc() function behaves identically
to malloc() for the specified size.
The free() function causes the allocated memory referenced by ptr to be made available for future allocations. If ptr is NULL, no action
occurs.
RETURN VALUES
The malloc() and calloc() functions return a pointer to the allocated memory if successful; otherwise a NULL pointer is returned and errno is
set to ENOMEM.
The realloc() function returns a pointer, possibly identical to ptr, to the allocated memory if successful; otherwise a NULL pointer is
returned, and errno is set to ENOMEM if the error was the result of an allocation failure. The realloc() function always leaves the original
buffer intact when an error occurs.
The free() function returns no value.
EXAMPLES
When using malloc(), be careful to avoid the following idiom:
if ((p = malloc(number * size)) == NULL)
err(EXIT_FAILURE, "malloc");
The multiplication may lead to an integer overflow. To avoid this, calloc() is recommended.
If malloc() must be used, be sure to test for overflow:
if (size && number > SIZE_MAX / size) {
errno = EOVERFLOW;
err(EXIT_FAILURE, "allocation");
}
When using realloc(), one must be careful to avoid the following idiom:
nsize += 50;
if ((p = realloc(p, nsize)) == NULL)
return NULL;
Do not adjust the variable describing how much memory has been allocated until it is known that the allocation has been successful. This can
cause aberrant program behavior if the incorrect size value is used. In most cases, the above example will also leak memory. As stated ear-
lier, a return value of NULL indicates that the old object still remains allocated. Better code looks like this:
newsize = size + 50;
if ((p2 = realloc(p, newsize)) == NULL) {
if (p != NULL)
free(p);
p = NULL;
return NULL;
}
p = p2;
size = newsize;
SEE ALSO
madvise(2), mmap(2), sbrk(2), alloca(3), atexit(3), getpagesize(3), memory(3), posix_memalign(3)
For the implementation details, see jemalloc(3).
STANDARDS
The malloc(), calloc(), realloc() and free() functions conform to ISO/IEC 9899:1990 (``ISO C90'').
BSD
May 3, 2010 BSD