Constructing Public or Private Keys |
All System V IPC objects can be constructed using a public key. There are two ways to construct either type of key in an object-oriented way.
Constructs the object with value value .
Constructs the object using filename and project_code as a seed. The filename variable must exist in the file system.
The second approach to allocating keys is useful when two or more projects are using System V IPC. As long as each project has a unique filename, the project allocates different keys. The two techniques for allocating keys are illustrated in the following example.
#include <iostream>
#include <ospace/unix.h>
// Name of project directory.
string project = "/usr/tmp";
int
main()
{
os_unix_toolkit initialize;
// Create key with specified id.
os_key key1( 10 );
cout << "key1 = " << key1 << endl;
// Create key using filename "/usr/tmp" and project code 1.
os_key key2( project, 1 );
cout << "key2 = " << key2 << endl;
// Create key using filename "/usr/tmp" and project code 2.
os_key key3( project, 2 );
cout << "key3 = " << key3 << endl;
return 0;
}
key1 = os_key( 10 )
key2 = os_key( 25575969 )
key3 = os_key( 42353185 )
Copyright©1994-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.