www.delorie.com/gnu/docs/gstep-core/gnustep-base.html   search  
 
Buy GNU books!


User's Guide to the GNUstep Base Library

[Top] [Contents] [Index] [ ? ]

User's Guide to the GNUstep Base Library

This manual documents some configuration and installation issues with the GNUstep Base Library and also differences between the Base Library and libraries that implement the OpenStep Foundation specification and the MacOS-X Foundation implementation.

1. Overview  
2. Configuration  
3. Special Features of gstep-base Classes  
4. Special Tools Included with gstep-base  
5. Installing GNU Objective-C Class Library  
6. Implementation Details  
Concept Index  

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1. Overview

*The GNUstep Base Library (gstep-base) requires the GNUstep Makefile Package (gstep-make) to compile. A recent GCC compiler may also be needed as well as other libraries. You should consult the `GNUstep-HOWTO' document that comes with the GNUstep Core Libraries package (gstep-core) or information on supported machines on the web site http://www.gnustep.org/information.

Documentation for individual classes is included in gsdoc (and html) format in the gsdoc directory.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2. Configuration

Configuration is performed by running the `configure' program at a shell prompt. You may want to use some of the optional arguments to the `configure' program. Type configure --help for a list of these. It is not likely that you will need to use the --prefix option, since gstep-base will automatically install in the directory specified by the GNUSTEP_SYSTEM_ROOT environment variable (specified when you installed gstep-make).

The only feature you may want to use is the --enable-pass-arguments or the --enable-fake-main option(s). Normally, the configure script will determine if a program can read process information directly from the system (for use by the class NSProcessInfo) and enable or disable the fake-main hack automatically, but if you find that configure is not doing this correctly, you can force the fake-main hack to be used, which will always work. Note that if the fake-main hack is enabled, you need to include the header file GSConfig.h in you main program -- this is done by default if you include NSObject.h or Foundation.h. If you want to avoid the whole idea of the fake-main hack, you can use the pass-arguments option. In this case you will be forced to call the NSProcessInfo initializeWithArguments method to pass the program arguments to NSProcessInfo (This would be done automatically if you use the NSApplicationMain function in a gui application).

Most other important configuration options are already set when you configure the gstep-make package.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3. Special Features of gstep-base Classes


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4. Special Tools Included with gstep-base


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5. Installing GNU Objective-C Class Library

Type make install to install the libraries and programs


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6. Implementation Details

6.1 Memory Management  
6.2 Memory Allocation  
6.3 Reference Counting  
6.4 Garbage Collection  
6.5 Time Zones  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1 Memory Management

The OpenStep standard defines an reference-count based memory management scheme which the GNUstep libraries support. GNUstep also supports garbage collection using the Boehm conservative garbage collecting library, though this is currently (October 1999) in a pre-alpha state.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.2 Memory Allocation

Normally, memory is allocated in zones. Most memory is allocated from a default area (returned by the NSDefaultMallocZone()) function. In some cases where you want to ensure that a group of objects are all located in roughly the same area of memory (for performance reasons) you might create a special zone large enough to accomodate the objects you wish to create, and allocate the objects from that area. This will minimise the paging that your application needs to do in accessing those objects frequently. With the low price of RAM in modern systems, paging is likely to be much less of a problem nowadays, and the need for zoning memory is much lower than it used to be.

At a low-level, memory allocation is performed by two functions - NSAllocateObject() and NSDeallocateObject(), but you need never normally deal with these functions - they are there for when you need an unusual degree of control or performance. These are the functions called by [NSObject +allocWithZone:] and [NSObject -dealloc]. If you call NSAllocateObject() directly to create an instance of a class, you may break some functionality of that class (such as caching of frequently used objects).

Generally, objects are created using the methods +alloc, -copy, -mutableCopy and are destroyed using -dealloc. The allocation methods are covers for the more versatile +allocWithZone:, -copyWithZone: and -mutableCopyWithZone: methods (which specify the zone from which the memory is to be allocated, rather than forcing you to use the default zone). NSObject also provides +new, which is simply a cover for the combination of a +alloc and a -init.

The -dealloc method returns the memory occupied by the object to the zone from which it was originally allocated, it can use the -zone method to determine which zone this is.

Explicit memory allocation and deallocation is efficient - but when you pass objects around inside a program (and especially from/to libraries etc) it quickly becomes difficult and/or inefficient to keep track of who owns an object and should be responsible for calling it's deallocation method.

To take this problem away, some mechanism is needed. The OpenStep specification provides a reference counting mechanism along with a set of conventions that make memory management easy. In addition to this, the GNU Objective-C compiler and the GNUstep system provide a memory sweeping garbage collection mechanism (using the Boehm conservative garbage collection library).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.3 Reference Counting

The reference counting scheme for object allocation/deallocation is quite simple. Objects are normally created with a reference count of 1. An objects reference count may be increased by callsing -retain, and decreased by calling -release. If a -release would make the reference count become zero, the -dealloc method is automatically called to destroy the object - freeing its memory.

This simple scheme then becomes more complicated with the addition of the -autorelease method. When -autorelease is called for an object, the object is added to the currently active autorelease pool. When the autorelease pool is later destroyed, every object in the pool will have a -release message sent to it for each time it was added to the pool. Thus, sending an -autorelease method to an object is equivalent to sending a -release at some future point.

In general, when a method (other than the alloc..., copy..., mutableCopy... and new... methods) returns an object, that object will have been autoreleased, so you don't need to worry about releasing it yourself. However, if you wish to store the object for any length of time, you will need to send it a retain message, and then send it a release when you have finished with it.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.4 Garbage Collection


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.5 Time Zones

If the GNUstep time zone datafiles become too out of date, one can download an updated database from ftp://elsie.nci.nih.gov/pub/ and compile it as specified in the README file in the NSTimeZones directory. (In fact, I believe it's about time they're updated.)

 
    Time zone names in NSDates should be GMT, MET etc. not
    Europe/Berlin, America/Washington etc.

The problem with this is that various time zones may use the same abbreviation (e.g. Australia/{Brisbane,...} and America/{New_York,...} both use EST), and some time zones may have different rules for daylight saving time even if the abbreviation and offsets from UTC are the same.

The problems with depending on the OS for providing time zone info are that some methods for the NSTimeZone classes might be difficult to implement, and also that time zone names may vary wildly between OSes (this could be a big problem when archiving is used between different systems).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Concept Index


[Top] [Contents] [Index] [ ? ]

Table of Contents

[Top] [Contents] [Index] [ ? ]

Short Table of Contents

1. Overview
2. Configuration
3. Special Features of gstep-base Classes
4. Special Tools Included with gstep-base
5. Installing GNU Objective-C Class Library
6. Implementation Details
Concept Index
[Top] [Contents] [Index] [ ? ]

About this document

This document was generated by DJ Delorie on June, 23 2003 using texi2html

The buttons in the navigation panels have the following meaning:

Button Name Go to From 1.2.3 go to
[ < ] Back previous section in reading order 1.2.2
[ > ] Forward next section in reading order 1.2.4
[ << ] FastBack previous or up-and-previous section 1.1
[ Up ] Up up section 1.2
[ >> ] FastForward next or up-and-next section 1.3
[Top] Top cover (top) of document  
[Contents] Contents table of contents  
[Index] Index concept index  
[ ? ] About this page  

where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003