10-03-2011
1. Stop using malloc()/calloc() and free() every time you need memory. Get ONE chunk of memory and reuse it. For example, pass a character buffer into a method instead of using calloc() to allocate a new one each and every time.
2. Fix your memory leaks - I spotted at least two, on in file_name_generator(), one caused by the return value of file_name_generator() overwriting a malloc()'d pointer.
3. Don't EVER use fgetc().
4. Don't read files TWICE. Use something like fgets() and process each word as you read it. If you're using rewind(), you've done something wrong.
This User Gave Thanks to achenle For This Post:
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi All
I have approximately 10 files that are at least 100+ MB in size. I am importing them into a DB to output them to the web. What i need to do first is clean the files up so i dont have un necessary rows in the DB. Below is what the file looks like:
Ignore the <TAB> annotations as that... (4 Replies)
Discussion started by: caddyjoe77
4 Replies
2. Programming
For reading in large text files (say files over 1kB in size) are there any issues with fopen() that I should be aware of ?
cheers (2 Replies)
Discussion started by: JamesGoh
2 Replies
3. Programming
Hi,
I'm trying to figure out the best solution to the following problem, and I'm not
yet that much experienced like you. :-)
Basically I have to read a fairly large file, composed of "messages" , in order
to display all of them through an user interface (made with QT).
The messages that... (3 Replies)
Discussion started by: emitrax
3 Replies
4. Shell Programming and Scripting
Hi Everyone,
I am using a centos 5.2 server as an sflow log collector on my network. Currently I am using inmons free sflowtool to collect the packets sent by my switches. I have a bash script running on an infinate loop to stop and start the log collection at set intervals - currently one... (2 Replies)
Discussion started by: lord_butler
2 Replies
5. UNIX for Dummies Questions & Answers
Hi,
I'm a newbie to shell scripting and I have the following problem:
I need all spaces between two letters or a letter and a number exchanged for an underscore, but all spaces between a letter and other characters need to remain. Searching forums didn't help...
One example for clarity:
... (3 Replies)
Discussion started by: Cpt_Cell
3 Replies
6. Shell Programming and Scripting
Hello,
Sorry for my bad english.
I need to improve performance in project managing large data, these data are exported to a MySql from XML.
Now I use PHP (XMLReader ()) to do this job.
I need a faster way to do this process.
Which do you think is the best way?
Example:
(the item... (2 Replies)
Discussion started by: stendelis
2 Replies
7. Shell Programming and Scripting
Dear all
From below mention input file I needed op file as show below. I am using below code but not worked.
I/p file
BSCBCH1 EXAL-1-4 WO* SMPS MAINS FAIL
BSCBCH1 EXAL-1-5 WO* SMPS RECTIFIER FAIL
BSCBCH1 EXAL-1-6 WO* SMPS MAJOR ALARM
BSCBCH2 EXAL-1-10 WO* ... (5 Replies)
Discussion started by: jaydeep_sadaria
5 Replies
8. UNIX for Dummies Questions & Answers
Hi,
I am trying to remove a string ".var" using the below command but it's not working as expected, when I execute this in the command prompt using the echo it's working fine , please let me know where I am doing it wrong.
UYRD=$FILE_$timestamp.csv | awk '{gsub(".var", "");print}' # this is... (6 Replies)
Discussion started by: shruthidwh
6 Replies
9. Shell Programming and Scripting
What I need is to remove the text from Location_file.txt from each line matching all entries from Remove_location.txt
Location_file.txt
FlowPrePaid, h3nmg1cm2,Jamaica_MTAImageFileFlowPrePaid,h0nmg1cm1, Flow_BeatTest,FlowRockTest
FlowNewTest,FlowNewTest,h0nmg1cm1
PartiallySubscribed,... (3 Replies)
Discussion started by: ketanraut
3 Replies
MALLOC(2) System Calls Manual MALLOC(2)
NAME
malloc, free, realloc, calloc - memory allocator
SYNOPSIS
#include <u.h>
#include <libc.h>
void* malloc(long size)
void free(void *ptr)
void* realloc(void *ptr, long size)
void* calloc(long nelem, long elsize)
DESCRIPTION
Malloc and free provide a simple memory allocation package. Malloc returns a pointer to a new block of at least size bytes. The block is
suitably aligned for storage of any type of object. No two active pointers from malloc will have the same value.
The argument to free is a pointer to a block previously allocated by malloc; this space is made available for further allocation. It is
legal to free a null pointer; the effect is a no-op.
Realloc changes the size of the block pointed to by ptr to size bytes and returns a pointer to the (possibly moved) block. The contents
will be unchanged up to the lesser of the new and old sizes. The call realloc(0, size) means the same as
Calloc allocates space for an array of nelem elements of size elsize. The space is initialized to zeros. Free frees such a block.
Alef
Except for calloc, these routines are available from Alef; they use the same arena as alloc. Malloc and realloc execute a check when they
fail, rather than return nil. Memory returned by malloc is cleared. Realloc does not guarantee new memory is cleared unless ptr is nil.
SOURCE
/sys/src/libc/port/malloc.c
SEE ALSO
brk(2)
DIAGNOSTICS
Malloc, realloc and calloc return 0 if there is no available memory. Errstr is likely to be set.
BUGS
The different specification of calloc is bizarre.
User errors can corrupt the storage arena. The most common gaffes are (1) freeing an already freed block, (2) storing beyond the bounds of
an allocated block, and (3) freeing data that was not obtained from the allocator. When malloc and free detect such corruption, they
abort.
MALLOC(2)