Sponsored Content
Full Discussion: C - Freeing resources
Top Forums Programming C - Freeing resources Post 302306741 by james2432 on Monday 13th of April 2009 04:33:53 PM
Old 04-13-2009
Quote:
Originally Posted by pludi
Code:
char string[10];
string[3] = 'A';

would you have to free(string) after?
Quote:
is the same as
Code:
char *string = (char *)malloc(10 * sizeof(char));
*(string + 3) = 'A';

And modifying multiple values in one function/method without pointers is virtually impossible.
you would have to free(string) here no matter what right?
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Who is using up all of my resources?!

For some reason, I'm having a bit of a brain fart here and cannot think of a simple solution to this problem... We have a samba server installed on one of our Darwin boxes. Someone is doing massive amounts of work through a samba share, and in turn in pegging samba and the box. I can see how... (1 Reply)
Discussion started by: fender177
1 Replies

2. UNIX for Dummies Questions & Answers

Freeing up a serial port with a modem connected

I currently access a remote Unix server which has an external modem connected to one of it's serial ports (/dev/cua/b). At times, this server undergoes a hard reset and for some reason this disallows us from making use of the modem any longer. A hard reset of the modem always seems to fix the... (0 Replies)
Discussion started by: ebender1
0 Replies

3. Solaris

CPU resources

Hi, I got a solarsi 10 box with 9 zones and the cpu shares as following ID NAME SHARES 0 global 1 1 FMW1 100 2 FMW2 100 3 OID1 100 4 OID2 100 5 OVD1 100 6 OID0 100 7 FMW5 100 8... (2 Replies)
Discussion started by: fugitive
2 Replies

4. UNIX for Dummies Questions & Answers

Trouble freeing memory after ctrl+D

Hello, I am trying to free memory allocation after EOF from keyboard is detected (ctrl+D) in a C program. I've written a small program to replicate my problem: int main(int argc, char *argv) { char *line; line = (char*)malloc(sizeof(char)*(512)); line = fgets(line, 512,... (1 Reply)
Discussion started by: oddworld
1 Replies

5. Programming

Trouble freeing memory after ctrl+D

Hello, I am trying to free memory allocation after EOF from keyboard is detected (ctrl+D) in a C program. I've written a small program to replicate my problem: int main(int argc, char *argv) { char *line; line = (char*)malloc(sizeof(char)*(512)); line = fgets(line, 512,... (10 Replies)
Discussion started by: oddworld
10 Replies

6. Boot Loaders

Bootloader Resources

Here is a list of resources for Unix and GNU/Linux bootloaders: GRUB Legacy: The original GRand Unified Bootloader. Now known as GRUB Legacy. GRUB: The latest and greatest. More commonly known as GRUB2. BRUG: Brand-new Universal loadeR from GRUB. Based on GRUB. Adds features like new object... (0 Replies)
Discussion started by: fpmurphy
0 Replies

7. Shell Programming and Scripting

Freeing the terminal from busy shell script?

Hi guys, I wrote a basic inotifywait shell script on my CentOS 5.6 x86_64 test server that syncs any deleted files in a directory. /usr/bin/script #!/bin/sh inotifywait -m -e delete /home/user/test | while read file; do # log event here done The script alone works fine. However, the... (4 Replies)
Discussion started by: TECK
4 Replies

8. UNIX for Dummies Questions & Answers

UNIX Openserver ver 5.0 freeing up space.

:)Hi all, Please advice me is it safer to use the following command to free up (truncate) space in HDD. 1) > /usr/adm/messages 2) > /usr/adm/sulog 3) > /usr/adm/ctlog 4) > /tmp 5) > /usr/adm/sa 6) > /var/spool Thanks in advance Rukshan (1 Reply)
Discussion started by: rukshan4u2c
1 Replies
GC_MALLOC(1L)															     GC_MALLOC(1L)

NAME
GC_malloc, GC_malloc_atomic, GC_free, GC_realloc, GC_enable_incremental, GC_register_finalizer, GC_malloc_ignore_off_page, GC_mal- loc_atomic_ignore_off_page, GC_set_warn_proc - Garbage collecting malloc replacement SYNOPSIS
#include "gc.h" void * GC_malloc(size_t size); void GC_free(void *ptr); void * GC_realloc(void *ptr, size_t size); cc ... gc.a DESCRIPTION
GC_malloc and GC_free are plug-in replacements for standard malloc and free. However, GC_malloc will attempt to reclaim inaccessible space automatically by invoking a conservative garbage collector at appropriate points. The collector traverses all data structures accessible by following pointers from the machines registers, stack(s), data, and bss segments. Inaccessible structures will be reclaimed. A machine word is considered to be a valid pointer if it is an address inside an object allocated by GC_malloc or friends. In most cases it is preferable to call the macros GC_MALLOC, GC_FREE, etc. instead of calling GC_malloc and friends directly. This allows debugging versions of the routines to be substituted by defining GC_DEBUG before including gc.h. See the documentation in the include files gc_cpp.h and gc_allocator.h, as well as the gcinterface.html file in the distribution, for an alternate, C++ specific interface to the garbage collector. Note that C++ programs generally need to be careful to ensure that all allo- cated memory (whether via new, malloc, or STL allocators) that may point to garbage collected memory is either itself garbage collected, or at least traced by the collector. Unlike the standard implementations of malloc, GC_malloc clears the newly allocated storage. GC_malloc_atomic does not. Furthermore, it informs the collector that the resulting object will never contain any pointers, and should therefore not be scanned by the collector. GC_free can be used to deallocate objects, but its use is optional, and generally discouraged. GC_realloc has the standard realloc seman- tics. It preserves pointer-free-ness. GC_register_finalizer allows for registration of functions that are invoked when an object becomes inaccessible. The garbage collector tries to avoid allocating memory at locations that already appear to be referenced before allocation. (Such apparent ``pointers'' are usually large integers and the like that just happen to look like an address.) This may make it hard to allocate very large objects. An attempt to do so may generate a warning. GC_malloc_ignore_off_page and GC_malloc_atomic_ignore_off_page inform the collector that the client code will always maintain a pointer to near the beginning of the object (within the first 512 bytes), and that pointers beyond that can be ignored by the collector. This makes it much easier for the collector to place large objects. These are recommended for large object allocation. (Objects expected to be larger than about 100KBytes should be allocated this way.) It is also possible to use the collector to find storage leaks in programs destined to be run with standard malloc/free. The collector can be compiled for thread-safe operation. Unlike standard malloc, it is safe to call malloc after a previous malloc call was interrupted by a signal, provided the original malloc call is not resumed. The collector may, on rare occasion produce warning messages. On UNIX machines these appear on stderr. Warning messages can be filtered, redirected, or ignored with GC_set_warn_proc This is recommended for production code. See gc.h for details. Fully portable code should call GC_INIT from the main program before making any other GC calls. On most platforms this does nothing and the collector is initialized on first use. On a few platforms explicit initialization is necessary. And it can never hurt. Debugging versions of many of the above routines are provided as macros. Their names are identical to the above, but consist of all capi- tal letters. If GC_DEBUG is defined before gc.h is included, these routines do additional checking, and allow the leak detecting version of the collector to produce slightly more useful output. Without GC_DEBUG defined, they behave exactly like the lower-case versions. On some machines, collection will be performed incrementally after a call to GC_enable_incremental. This may temporarily write protect pages in the heap. See the README file for more information on how this interacts with system calls that write to the heap. Other facilities not discussed here include limited facilities to support incremental collection on machines without appropriate VM sup- port, provisions for providing more explicit object layout information to the garbage collector, more direct support for ``weak'' pointers, support for ``abortable'' garbage collections during idle time, etc. SEE ALSO
The README and gc.h files in the distribution. More detailed definitions of the functions exported by the collector are given there. (The above list is not complete.) The web site at http://www.hpl.hp.com/personal/Hans_Boehm/gc . Boehm, H., and M. Weiser, "Garbage Collection in an Uncooperative Environment", Software Practice & Experience, September 1988, pp. 807-820. The malloc(3) man page. AUTHOR
Hans-J. Boehm (Hans.Boehm@hp.com). Some of the code was written by others, most notably Alan Demers. 2 October 2003 GC_MALLOC(1L)
All times are GMT -4. The time now is 03:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy