Sponsored Content
Full Discussion: C - Freeing resources
Top Forums Programming C - Freeing resources Post 302306732 by pludi on Monday 13th of April 2009 04:08:12 PM
Old 04-13-2009
Quote:
Originally Posted by james2432
so it's essentially only if you want to reserve a segment of memory(to assure that it's always there)
Um, no. Statically allocated memory is always there, guaranteed (otherwise the program won't even start). Via malloc you ask the OS for some memory. If you get it, it's yours until you return it. If you don't your program has to cope with that (either complain to the user and/or try again later). It's the same in C#, if the VM doesn't have any memory left for objects you can't create them.
Quote:
Originally Posted by james2432
and to access via pointer later(not that I like using pointers)?
Good luck then, because in C/C++ there are very, very few things you can do without pointers. Arrays, for example:
Code:
char string[10];
string[3] = 'A';

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.
Quote:
Originally Posted by james2432
So the int would be freed after it hits the end of the block?
Code:
main
{
}<--would be freed here

That's 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
XmGetSecondaryResourceData(3X)											    XmGetSecondaryResourceData(3X)

NAME
XmGetSecondaryResourceData - A function that provides access to secondary widget resource data SYNOPSIS
#include <Xm/Xm.h> Cardinal XmGetSecondaryResourceData (widget_class, secondary_data_return) WidgetClass widget_class; XmSecondaryResourceData **secondary_data_return; DESCRIPTION
Some Motif widget classes (such as Gadget, Text, and VendorShell) have resources that are not accessible via the functions XtGetRe- sourceList and XtGetConstraintResourceList. To retrieve the descriptions of these resources, an application must use XmGetSecondaryRe- sourceData. When a widget class has such resources, this function provides descriptions of the resources in one or more data structures. XmGetSec- ondaryResourceData takes a widget class argument and returns the number of these data structures associated with the widget class. If the return value is greater than 0, the function allocates and fills an array of pointers to the corresponding data structures. It returns this array at the address that is the value of the secondary_data_return argument. The type XmSecondaryResourceData is a pointer to a structure with two members that are useful to an application: resources, of type XtRe- sourceList, and num_resources, of type Cardinal. The resources member is a list of the widget resources that are not accessible using Xt functions. The num_resources member is the length of the resources list. If the return value is greater than 0, XmGetSecondaryResourceData allocates memory that the application must free. Use XtFree to free the resource list in each structure (the value of the resources mem- ber), the structures themselves, and the array of pointers to the structures (the array with address secondary_data_return). Specifies the widget class for which secondary resource data is to be retrieved. Specifies a pointer to an array of XmSecondaryResourceData pointers to be returned by this function. If the widget class has no secondary resource data (i.e., if the value returned by the function is 0), the function returns no meaningful value for this argument. RETURN VALUES
Returns the number of secondary resource data structures associated with this widget class. EXAMPLES
The following example prints the names of the secondary resources of the Text widget and then frees the data allocated by the function: XmSecondaryResourceData * block_array ; Cardinal num_blocks, i, j ; if (num_blocks = XmGetSecondaryResourceData (xmTextWidgetClass, &block_array)) { for (i = 0; i < num_blocks; i++) { for (j = 0 ; j < block_array[i]->num_resources; j++) { printf("%s ", block_array[i]->resources[j].resource_name); } XtFree((char*)block_array[i]->resources); XtFree((char*)block_array[i]); } XtFree((char*)block_array); } XmGetSecondaryResourceData(3X)
All times are GMT -4. The time now is 01:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy