Sponsored Content
Full Discussion: C - Freeing resources
Top Forums Programming C - Freeing resources Post 302306746 by pludi on Monday 13th of April 2009 04:55:52 PM
Old 04-13-2009
In the first case you won't have to free at the end, as it's statically allocated, in the second you would have to, since it's dynamically allocated. In the first case you'd have to recompile every time you want to change the size of the string/array, which can be done at runtime in the second case.
 

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
PMPARSEHOSTSPEC(3)					     Library Functions Manual						PMPARSEHOSTSPEC(3)

NAME
__pmParseHostSpec, __pmUnparseHostSpec, __pmFreeHostSpec - uniform host specification parser C SYNOPSIS
#include <pcp/pmapi.h> #include <pcp/impl.h> int __pmParseHostSpec(const char *string, pmHostSpec **hostsp, int *count, char **errmsg); int __pmUnparseHostSpec(pmHostSpec *hosts, int count, char *string, size_t size); void __pmFreeHostSpec(pmHostSpec *hosts, int count); cc ... -lpcp DESCRIPTION
__pmParseHostSpec accepts a string specifying the location of a PCP performance metric collector daemon. The syntax of the various formats of this string is described in PCPIntro(1) where several examples are also presented. The syntax allows the initial pmcd(1) hostname to be optionally followed by a list of port numbers, which will be tried in order when con- necting to pmcd on that host. The portlist is separated from the hostname using a colon, and each port in the list is comma-separated. In addition, one or more optional pmproxy(1) hosts can be specified (currently, only one proxy host is supported by the PCP protocols). These are separated from each other and from the pmcd component using the @ character. These may also be followed by an optional port list, using the same comma-separated syntax as before. __pmParseHostSpec takes a null-terminated host specification string and returns an array of pmHostSpec structures, where the array has count entries. These pmHostSpec structures that are returned via hostsp represent each individual host in the specification string and has the following declaration: typedef struct { char *name; /* hostname (always valid) */ int *ports; /* array of host port numbers */ int nports; /* number of ports in host port array */ } pmHostSpec; __pmUnparseHostSpec performs the inverse operation, creating a string representation from a number of hosts structures. Where the count of structures indicated by hosts is greater than one, the proxy syntax is used to indicate a chain of proxied hosts. The size of the supplied string buffer must be provided by the caller using the size parameter. RETURN VALUE
If the given string is successfully parsed __pmParseHostSpec returns zero. In this case the dynamic storage allocated by __pmParseHostSpec can be released by calling __pmFreeHostSpec using the address returned from __pmParseHostSpec via hosts. __pmParseHostSpec returns PM_ERR_GENERIC and a dynamically allocated error message string in errmsg, if the given string does not parse, and the user-supplied errmsg pointer is non-null. Be sure to free(3C) the error message string in this situation. In the case of an error, hosts is undefined. In the case of success, errmsg is undefined. On success __pmUnparseHostSpec returns a positive value indicating the number of characters written into the supplied buffer. However, if the supplied buffer was too small, a negative status code of -E2BIG is returned. SEE ALSO
pmcd(1), pmproxy(1), pmchart(1), __pmParseHostAttrsSpec(3), PMAPI(3) and pmNewContext(3). Performance Co-Pilot PCP PMPARSEHOSTSPEC(3)
All times are GMT -4. The time now is 08:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy