| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (3 out of 5)

Guidelines for Minimizing Memory Use

Several techniques exist for minimizing memory use in a G2 application.

Select Memory-Efficient Data Structures

If memory consumption is a critical issue, you should try to minimize the memory requirement for classes that will have many instances. However, remember that minimizing memory for classes that do not account for a large percentage of memory consumption will have little impact on overall memory use.

To conserve memory, you should try to minimize the number of objects in your KB. It is more efficient to use arrays and lists, or sequences and structures than it is to use objects because the memory needed to store another value in an array or list is minimal, compared to the memory needed to create an entirely new object. For example, instead of storing data as 1000 objects, each with four attributes, consider storing the information as 4 value arrays, each with 1000 elements, thus saving 996 objects. Alternatively, you can store all the information in a single array or list by storing each item's information as four consecutive values. It is also more efficient to use messages as the superior class of user-defined classes, as opposed to objects, when you do not need an iconic representation of the object.

Also, try to define objects with subobjects only when necessary. It is more memory-efficient to have an object with ten attributes, rather than an object with five attributes, each of which is a subobject with two additional attributes.

Note that while these techniques minimize memory consumption, they also make your application more difficult to understand and debug. Therefore, you should only employ these techniques when memory consumption is a critical issue.

For more information, see the references in this table:

For information on... See...
Using messages as opposed to objects
Use Message as the Superior Class for Non-Iconic Classes
Using lists and arrays
Using Lists and Arrays to Represent Data Series
Using sequences and structures
Using Structures and Sequences to Represent Composite Data

Hide Name Boxes and Attribute Displays

Name boxes, which are the visible name of an item on a workspace, and attribute displays, which are the visible displays of item attributes, consume a surprising amount of memory, approximately 300 bytes. To conserve memory, try to minimize the number of items with name boxes and attribute displays.

If you are programmatically naming items and placing them on workspaces, you can avoid generating a name box by naming the item before transferring it to the workspace. You can also programmatically hide name boxes and attribute displays by using the attribute access facility of G2, which allows you conclude values directly into system-defined attributes.

For more information on accessing system-defined attributes, see Accessing System-Defined Attributes.

Minimizing Non-Functional Items

To reduce the size of your module, you should minimize the number of non-functional items, such as free text, workspaces, "go to workspace" buttons, and so on.

For more information on how to reduce the size of a module before deployment, see Creating a Release Manager Module.

| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (3 out of 5)

Copyright © 1997 Gensym Corporation, Inc.