Sheerpower Logo
R.10  Advanced Symbolic Value Pairs

Understanding and Using Symbolic Value Pairs

In Sheerpower, symbolic value pairs provide a powerful mechanism for sharing and maintaining data across processes and reboots. These symbolic values are divided into three types: globals, symbols, and logicals. In this tutorial, we’ll explore each type, provide examples of their usage, suggest practical applications, and conclude with key takeaways.

1. Globals: High-Speed Inter-Process Communication

What Are Globals?

Globals in Sheerpower persist as long as at least one Sheerpower process is running. Once all processes terminate, the globals are removed. Globals are extremely fast, capable of handling over 10 million reads and writes per second, making them perfect for rapid inter-process communication.

Example of Use:

set system, global "current_session": value "12345" ask system, global "current_session": value session_id$ print session_id$

In this example, we set a global symbol current_session with the value "12345". We then retrieve that value and print it.

Suggested Uses:

  1. Session Management: Store session IDs or user state across multiple processes for synchronized access.
  2. Task Coordination: Share task progress or state across Sheerpower processes without the need for a centralized database.
  3. Rapid Caching: Use globals as a high-speed cache for frequently accessed data between processes.

2. Symbols: Temporary Persistence Until Reboot

What Are Symbols?

Symbols persist until the next system reboot, at which point they are cleared. They are useful when you need temporary data storage that lasts beyond a single process but doesn’t need to survive reboots.

Example of Use:

set system, symbol "last_backup": value "2024-10-10" ask system, symbol "last_backup": value backup_date$ print backup_date$

Here, we set a symbolic value for the last backup date. We can ask for this value later, and it will persist until the machine reboots.

Suggested Uses:

  1. Temporary Configurations: Store temporary settings that should persist across sessions but reset after a reboot.
  2. Logging and Auditing: Maintain temporary logs of actions or events, cleared upon reboot.
  3. Shared Counters: Track counters or flags that need to persist across multiple processes but not beyond a system restart.

3. Logicals: Persistent Across Reboots

What Are Logicals?

Logicals are the most persistent form of symbolic values. They survive reboots and can even be used to represent file paths or other constants that need to remain available system-wide.

Example of Use:

set system, logical "project_path": value "C:\Projects\Sheerpower" ask system, logical "project_path": value path$ open file out_ch: name "project_path:mylog.txt", access output print path$

In this example, we store a logical path for a project directory. This value persists across reboots, ensuring it's always available.

Suggested Uses:

  1. File Path Management: Store frequently accessed file paths for consistent reference across system reboots.
  2. System-Wide Configuration: Maintain configuration settings or constants that must persist indefinitely.
  3. Network Resources: Reference network locations, shared drives, or resources that must persist across reboots.

Conclusion: Choosing the Right Symbolic Value Type

Sheerpower offers flexible symbolic value pairs that allow developers to store and share data efficiently:

  • Globals: Ideal for fast, inter-process communication and caching.
  • Symbols: Provide temporary persistence, useful for session-based data that doesn't need to outlast a reboot.
  • Logicals: Persist indefinitely and are perfect for file paths or system-wide settings.

By understanding the unique strengths of each symbolic type, you can ensure your Sheerpower applications are both robust and performant.

Hide Description

    

       


      

Enter or modify the code below, and then click on RUN

Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use.
Wide screen