Jump to content

SomBeginPersistentIds: Difference between revisions

From EDM2
Ak120 (talk | contribs)
mNo edit summary
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
This functions tells SOM to begin a "persistent ID interval."  
{{DISPLAYTITLE:somBeginPersistentIds}}
This functions tells SOM to begin a "persistent ID interval."


==Syntax==
==Syntax==
<PRE>
somBeginPersistentIds();
somBeginPersistentIds();
 
</PRE>
==Parameters==
==Parameters==
N/A
N/A
Line 12: Line 12:


==Remarks==
==Remarks==
This function informs the SOM ID manager that strings for any new SOM IDs that are registered will not be freed or modified. This allows the ID manager to use a pointer to the string in the unregistered ID as the master copy of the ID's string, rather than making a copy of the string. This makes ID handling more efficient.  
This function informs the SOM ID manager that strings for any new SOM IDs that are registered will not be freed or modified. This allows the ID manager to use a pointer to the string in the unregistered ID as the master copy of the ID's string, rather than making a copy of the string. This makes ID handling more efficient.


==Example Code==
==Example Code==
<PRE>
<PRE>
#include <som.h>
#include <som.h>
Line 53: Line 52:
==Related Functions==
==Related Functions==
* [[somCheckId]]
* [[somCheckId]]
*somRegisterId
* [[somRegisterId]]
*somIdFromString
* [[somIdFromString]]
*somStringFromId
* [[somStringFromId]]
*[[somCompareIds]]
* [[somCompareIds]]
*somTotalRegIds
* [[somTotalRegIds]]
*somUniqueKey
* [[somUniqueKey]]
*somSetExpectedIds
* [[somSetExpectedIds]]
*somEndPersistentIds
* [[somEndPersistentIds]]


[[Category:SOM Kernel]]
[[Category:SOM function]]

Latest revision as of 02:21, 6 May 2020

This functions tells SOM to begin a "persistent ID interval."

Syntax

somBeginPersistentIds();

Parameters

N/A

Return Code

  • rc

Remarks

This function informs the SOM ID manager that strings for any new SOM IDs that are registered will not be freed or modified. This allows the ID manager to use a pointer to the string in the unregistered ID as the master copy of the ID's string, rather than making a copy of the string. This makes ID handling more efficient.

Example Code

#include <som.h>
/* This is the way to create somIds efficiently */
static string id1Name = "whoami";
static somId somId_id1 = &id1Name;
/*
   somId_id1 will be registered the first time it is used
   in an operation that takes a somId, or it can be explicitly
   registered using somCheckId.
*/

main()
{
   somId id1, id2;
   string id2Name = "whereami";

   somEnvironmentNew();
   somBeginPersistentIds();
   id1 = somCheckId(somId_id1); /* registers the id as persistent */
   somEndPersistentIds();
   id2 = somIdFromString(id2Name); /* registers the id */

   SOM_Assert(!strcmp("whoami", somStringFromId(id1)), SOM_Fatal);
   SOM_Assert(!strcmp("whereami", somStringFromId(id2)), SOM_Fatal);

   id1Name = "it does matter"; /* because it is persistent */
   id2Name = "it doesn't matter"; /* because it is not persistent */

   SOM_Assert(strcmp("whoami", somStringFromId(id1)), SOM_Fatal);
   /* The id1 string has changed */
   SOM_Assert(!strcmp("whereami", somStringFromId(id2)), SOM_Fatal);
   /* the id2 string has not */
}

Related Functions