VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Non-Volatile RAM (using disk files)

by James Vincent Carnicelli (21 Submissions)
Category: Data Structures
Compatability: Visual Basic 3.0
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (5 Votes)

Conceptually, non-volatile RAM is any RAM (random access memory) that is not lost because the memory device loses (external) power. The NvRam class implements this in a primitive but powerful way: by writing to and reading from a data file in real time. In principle, your code need only identify the location in this "memory" (as in an array) that a given variable is stored in and the class does the rest.

Here's a simple example of how it works:



    Dim MyVar As Long

    Set Nvr = New NvRam

    Nvr.Connect "C:\MyData.dat"


    'Read in value,

    'do something with it,

    'and write it back out.


    Nvr.ReadVar MyVar, 20

    MyVar = MyVar + 1

    Nvr.WriteVar MyVar, 20


    Nvr.Disconnect




Here are some good applications for this class:

- Protecting in-"memory" data from power failures.

- Maintaining large amounts of data with almost no memory overhead.

- Maintaining program state across run-time sessions.

- Sharing data among multiple processes.

While it does not yet have built-in support for storing user-defined data types or objects, all primitive data types (e.g., Long and String)
are supported. (Variants are allowed, so long as they are late-bound to one of the primitive data types.) Also missing is a way to shrink the size of the data file, the equivalent of ReDim Preserve. Feel free to make suggestions or add support for such features, so long as credit is given for the original code.

While tested with VB6/NT4, this should be compatible with any version of Windows that supports the CopyMemory() API call and which has data types with the same sizes as with Win32 systems like NT. Your comments and vote are welcome.

Rate Non-Volatile RAM (using disk files)

Download Non-Volatile RAM (using disk files)

Download Non-Volatile RAM (using disk files) (4 KB)

Non-Volatile RAM (using disk files) Comments

No comments have been posted about Non-Volatile RAM (using disk files). Why not be the first to post a comment about Non-Volatile RAM (using disk files).

Post your comment

Subject:
Message:
0/1000 characters