SomAllocate: Difference between revisions
No edit summary |
mNo edit summary |
||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:somAllocate}} | {{DISPLAYTITLE:somAllocate}} | ||
This method supports class-specific memory allocation for class instances. It cannot be overridden. | This method supports class-specific memory allocation for class instances. It cannot be overridden. | ||
For backward compatibility, this method does not take an Environment parameter. | For backward compatibility, this method does not take an Environment parameter. | ||
;Original Class: [[SOMClass]] | |||
==Syntax== | ==Syntax== | ||
<PRE> | <PRE> | ||
Line 15: | Line 16: | ||
==Parameters== | ==Parameters== | ||
; receiver (SOMClass) : A pointer to the class object whose memory allocation method is desired. | ;receiver (SOMClass) : A pointer to the class object whose memory allocation method is desired. | ||
;size (long) : The number of bytes to be allocated. | |||
; size (long) : The number of bytes to be allocated. | |||
==Return Code== | ==Return Code== | ||
;rc (string) : | |||
; rc (string) : | string A pointer to the first byte of the allocated memory region. | ||
NULL If sufficient memory is not available. | |||
string A pointer to the first byte of the allocated memory region. | |||
NULL If sufficient memory is not available. | |||
==Remarks== | ==Remarks== | ||
When building a class, the somBuildClass function is responsible for registering the procedure that will be executed when this method is invoked on the class. The default procedure registered by somBuildClass uses the SOMMalloc function, but the IDL | When building a class, the somBuildClass function is responsible for registering the procedure that will be executed when this method is invoked on the class. The default procedure registered by somBuildClass uses the SOMMalloc function, but the IDL modifier somallocate can be used in the SOM IDL class implementation section to indicate a different procedure. Users of this method should be sure to use the dual method, somDeallocate, to free allocated storage. Also, if the IDL modifier somallocate is used to indicate a special allocation routine, the IDL modifier somdeallocate should be used to indicate a dual procedure to be called when the somDeallocate method is invoked. | ||
==Example Code== | ==Example Code== | ||
Line 39: | Line 37: | ||
string newRegion = _SOMClass->somAllocate(20); | string newRegion = _SOMClass->somAllocate(20); | ||
} | } | ||
</PRE> | </PRE> | ||
Latest revision as of 16:30, 12 October 2022
This method supports class-specific memory allocation for class instances. It cannot be overridden.
For backward compatibility, this method does not take an Environment parameter.
- Original Class
- SOMClass
Syntax
SOMClass receiver; long size; string rc; rc = somAllocate(receiver, size);
Parameters
- receiver (SOMClass)
- A pointer to the class object whose memory allocation method is desired.
- size (long)
- The number of bytes to be allocated.
Return Code
- rc (string)
string A pointer to the first byte of the allocated memory region. NULL If sufficient memory is not available.
Remarks
When building a class, the somBuildClass function is responsible for registering the procedure that will be executed when this method is invoked on the class. The default procedure registered by somBuildClass uses the SOMMalloc function, but the IDL modifier somallocate can be used in the SOM IDL class implementation section to indicate a different procedure. Users of this method should be sure to use the dual method, somDeallocate, to free allocated storage. Also, if the IDL modifier somallocate is used to indicate a special allocation routine, the IDL modifier somdeallocate should be used to indicate a dual procedure to be called when the somDeallocate method is invoked.
Example Code
#include <som.xh> #<somcls.xh> main() { SOMClassMgr *cm = somEnvironmentNew(); /* Use SOMClass's instance allocation method */ string newRegion = _SOMClass->somAllocate(20); }
Related
Methods
- somDeallocate