This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com

Home

 
4D v19.8
Storage

Storage 


 

Storage -> Function result 
Parameter Type   Description
Function result  Object in Catalog of shared objects and shared collections registered in Storage

The Storage method returns the catalog of shared objects or shared collections that you have registered in the Storage object on the current machine or component.

The catalog returned by Storage is automatically created by 4D and is available to all processes of the database, including preemptive processes. There is one Storage catalog per machine and component: in a client/server application, there is one Storage shared object on the server, and one Storage shared object on each remote 4D application; if the database uses components, there is one Storage object per component.

Use the Storage catalog to reference any shared objects or shared collections that you want to be used from any preemptive or standard process. To register a shared object or a shared collection in the catalog, add its reference to the shared object returned by Storage.

Since the catalog returned by Storage is a shared object, it follows the rules described in the Shared objects and shared collections section, but with some specificities:

  • This object can only contain shared objects and shared collections. Trying to add other kinds of values (non-shared objects or collections, null, scalar values) will generate an error.
  • Adding a property to this object must be surrounded by the Use...End use structure, otherwise an error is returned. Reading an attribute outside of a Use...End use structure is, however, possible.
  • When surrounded by the Use...End use structure, first-level attributes of Storage are locked for other processes.
  • Unlike standard shared objects, the object returned by Storage will NOT share its locking identifier with shared objects or collections added as attributes (for more information, refer to the About the locking identifier (how shared groups work) section).

A common practice could be initializing the Storage object in the : 

 Use(Storage)
    Storage.counters:=New shared object("customers";0;"invoices";0)
 End use

This example shows a standard way to set Storage values:

 Use(Storage)
    Storage.mydata:=New shared object
    Use(Storage.mydata)
       Storage.mydata.prop1:="Smith"
       Storage.mydata.prop2:=100
    End use
 End use

Storage allows implementing a singleton with a lazy initialization, as shown in the following example.

Note: For more information about singleton patterns, you can refer to this Wikipedia page.

 C_LONGINT($0)
 C_LONGINT($counterValue)
 C_OBJECT(counter//create a reference to counter for the process
 
 If(counter=Null//if this reference is null, get if from Storage
    Use(Storage//Use of Storage needed only once!
       If(Storage.counter=Null)
          Storage.counter:=New shared object("operation";0)
       End if
       counter:=Storage.counter //Get the reference of the counter shared object
    End use
 End if
 Use(counter) //directly use the shared object counter (no need to use Storage!)
    counter.operation:=counter.operation+1
    $counterValue:=counter.operation
 End use
 
 $0:=$counterValue



See also 

Shared objects and shared collections

 
PROPERTIES 

Product: 4D
Theme: Objects (Language)
Number: 1525

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v16 R6

 
ARTICLE USAGE

4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)
4D Language Reference ( 4D v19.4)
4D Language Reference ( 4D v19.5)
4D Language Reference ( 4D v19.6)
4D Language Reference ( 4D v19.7)
4D Language Reference ( 4D v19.8)