Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

...and scantily clad females, of course. Who cares if it's below zero outside. -- Linus Torvalds


devel / comp.lang.c / Detect wrap-around on array

SubjectAuthor
* Detect wrap-around on arraypozz
+* Re: Detect wrap-around on arrayScott Lurndal
|`- Re: Detect wrap-around on arrayScott Lurndal
+- Re: Detect wrap-around on arrayDavid Brown
+- Re: Detect wrap-around on arrayKaz Kylheku
+- Re: Detect wrap-around on arrayBen Bacarisse
+* Re: Detect wrap-around on arraypozz
|`- Re: Detect wrap-around on arrayVir Campestris
`- Re: Detect wrap-around on arrayjak

1
Detect wrap-around on array

<uib6g7$dgtq$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30243&group=comp.lang.c#30243

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: pozzu...@gmail.com (pozz)
Newsgroups: comp.lang.c
Subject: Detect wrap-around on array
Date: Mon, 6 Nov 2023 18:07:19 +0100
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <uib6g7$dgtq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 6 Nov 2023 17:07:19 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f149d65dac7ee07f06bf78fdf6b98fbd";
logging-data="443322"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//sNOT8e0twODDpbWFU+/kmK+TVOUtp2k="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:y/Qi899KIkYbbyQ0atqoFVA3cQM=
Content-Language: it
 by: pozz - Mon, 6 Nov 2023 17:07 UTC

I have an array of structs. Its dimension is fixed:

#define ARRAY_SIZE 200
struct mystruct array[ARRAY_SIZE];

This array is saved into a binary file with fwrite() and loaded in RAM
at startup.

During its run, the application could save a new entry in the array,
starting from index 0. When the array is full, the new entry will be
written to index 0 again, overwriting oldest entry. From this moment on,
the number of entries in the array remains constant at ARRAY_SIZE.

The application can be closed and restarted at any moment and, at
startup, the last situation must be restored from the saved file.

In order to understand what is the next position for the new entry, how
many entries are stored in the array and so on, the struct has two
members: a 16 bits unsigned integer ID and boolean valid flag.

struct mystruct {
bool valid;
uint16_t id;
struct myentry entry;
}

Initially the array is initialized with valid members to false.

Now, I'm trying to write the startup function that, after loading the
array from file to RAM, should detect what is the next entry position,
how many entries are stored in the array and so on.

It's very simple if less than 65536 entries have been added to the
array. It's sufficient to search the entry with the maximum ID.
What happens if one more entry is added? The new entry ID will be zero,
that is the lowest ID in the array, but it's the newest entry in the array.

Any help? I suspect the solution is in the difference of unsigned integers.

Re: Detect wrap-around on array

<KI92N.39576$EUq9.7162@fx41.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30244&group=comp.lang.c#30244

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx41.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Detect wrap-around on array
Newsgroups: comp.lang.c
References: <uib6g7$dgtq$1@dont-email.me>
Lines: 25
Message-ID: <KI92N.39576$EUq9.7162@fx41.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Mon, 06 Nov 2023 17:51:38 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Mon, 06 Nov 2023 17:51:38 GMT
X-Received-Bytes: 1467
 by: Scott Lurndal - Mon, 6 Nov 2023 17:51 UTC

pozz <pozzugno@gmail.com> writes:
>I have an array of structs. Its dimension is fixed:
>
> #define ARRAY_SIZE 200
> struct mystruct array[ARRAY_SIZE];
>
>This array is saved into a binary file with fwrite() and loaded in RAM
>at startup.
>
>During its run, the application could save a new entry in the array,
>starting from index 0. When the array is full, the new entry will be
>written to index 0 again, overwriting oldest entry. From this moment on,
>the number of entries in the array remains constant at ARRAY_SIZE.

Generally known as a ring buffer.

https://en.wikipedia.org/wiki/Circular_buffer

Which requires metadata (head and tail pointers, generally
when the producer and consumer are distinct).

Use 'mmap' instead of fwrite() [on posix systems] and include
a fixed header before the ring buffer containing metadata
like the head/tail pointers, capacity, etc.

Re: Detect wrap-around on array

<uibbic$iseh$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30246&group=comp.lang.c#30246

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Detect wrap-around on array
Date: Mon, 6 Nov 2023 19:33:48 +0100
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <uibbic$iseh$1@dont-email.me>
References: <uib6g7$dgtq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 6 Nov 2023 18:33:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9b81374a8a5c74364f583f3744115189";
logging-data="618961"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/w/2zw+YAYWGrza+4agdl9BawaQgzFYec="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Dd4dhggwowZaiDqW9jmcumfB3x8=
In-Reply-To: <uib6g7$dgtq$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Mon, 6 Nov 2023 18:33 UTC

On 06/11/2023 18:07, pozz wrote:
> I have an array of structs. Its dimension is fixed:
>
>   #define ARRAY_SIZE            200
>   struct mystruct array[ARRAY_SIZE];
>
> This array is saved into a binary file with fwrite() and loaded in RAM
> at startup.
>
> During its run, the application could save a new entry in the array,
> starting from index 0. When the array is full, the new entry will be
> written to index 0 again, overwriting oldest entry. From this moment on,
> the number of entries in the array remains constant at ARRAY_SIZE.
>
> The application can be closed and restarted at any moment and, at
> startup, the last situation must be restored from the saved file.
>
> In order to understand what is the next position for the new entry, how
> many entries are stored in the array and so on, the struct has two
> members: a 16 bits unsigned integer ID and boolean valid flag.
>
>   struct mystruct {
>     bool valid;
>     uint16_t id;
>     struct myentry entry;
>   }
>
> Initially the array is initialized with valid members to false.
>
> Now, I'm trying to write the startup function that, after loading the
> array from file to RAM, should detect what is the next entry position,
> how many entries are stored in the array and so on.
>
> It's very simple if less than 65536 entries have been added to the
> array. It's sufficient to search the entry with the maximum ID.
> What happens if one more entry is added? The new entry ID will be zero,
> that is the lowest ID in the array, but it's the newest entry in the array.
>
> Any help? I suspect the solution is in the difference of unsigned integers.

I'm not sure I follow the exact requirements here. But I'd start by
thinking about a maximum number of element additions that is feasible
for the application - clearly 2 ^ 16 is not enough, but 2 ^ 32 might be,
and 2 ^ 64 certainly will be. Replace the "bool valid; uint16_t id;"
with either "uint32_t id;" or "uint64_t id;", where id 0 is used for
"not valid". (The stored id will thus be one more than the index.)
There's no possibility of overflow, solving that problem.

Re: Detect wrap-around on array

<20231106095723.173@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30247&group=comp.lang.c#30247

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Detect wrap-around on array
Date: Mon, 6 Nov 2023 18:54:04 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <20231106095723.173@kylheku.com>
References: <uib6g7$dgtq$1@dont-email.me>
Injection-Date: Mon, 6 Nov 2023 18:54:04 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="1ea8bf42c687cc3b3e82603f8a9aab63";
logging-data="627656"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18FGb6bf3GOgk5r2h+THUDRKvcqC3x7W4U="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:XkEINYU5mlYdMJMG6VHfGOyIhoo=
 by: Kaz Kylheku - Mon, 6 Nov 2023 18:54 UTC

On 2023-11-06, pozz <pozzugno@gmail.com> wrote:
> Any help? I suspect the solution is in the difference of unsigned integers.

The entry IDs are normally consecutive integers. When they wrap, they
jump to zero. Whenever the wraparound happens, the buffer contains
nothing but IDs that are in the range 65336-65535. The 65336 is the
least recent ID, which will be the victim, overwritten by 0.

Thus, when we scan the buffer, we can divide the situation into these
exhaustive cases:

1. there are entries with IDs in the range range 65337 to 65535
a) there are entries present from the ID range 0 to 198
b) no such entries.

2. there aren't.

In case 1 (a), we know we are in the wrapped situation, and and we
must find the highest ID among the 0 to 198 range.

In the other cases, we look for the highest absolute ID.

In case 1 (b), IDs in the 65537+ range are occurring already, but
wrap around has not yet taken place, so there are no 0 to 198 IDs.
Only high ones below 65537.

In case 2, we are near wraparound yet. The initial state falls into
this camp. (The buffer should be initialized so that the IDs are all
zero.)

I suspect this can be done in one pass. Make a pass through the
array, and collect this information:

A. What is the highest ID, in the range 0 to 198? (Use the value
65535 if it doesn't exist.)

B. What is the absolutely highest ID?

C. Are there IDs in the range 65537+

From that, you have everythign you need. If from (A) you get
a value other than 65535, and (C) indicates yes, then we are in
case 1 (a), and so the value from (A) is the highest ID. Otherwise the
value from (B) is the highest ID. We save the positions as well, in the
same pass.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Detect wrap-around on array

<87y1fa4pwx.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30248&group=comp.lang.c#30248

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Detect wrap-around on array
Date: Mon, 06 Nov 2023 19:55:58 +0000
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <87y1fa4pwx.fsf@bsb.me.uk>
References: <uib6g7$dgtq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="ed0e70747df064569d1810ad3d9e9c8e";
logging-data="650209"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Ke1Whdo8NmR0yD/i/msdrONHzcEJiclw="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:CvEm/c1aQujlnil8xj0CaedzDZg=
sha1:FoyEc1bCYsHnC13eEpNlLYqoCf0=
X-BSB-Auth: 1.6012250ce221fe3ebdb0.20231106195558GMT.87y1fa4pwx.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 6 Nov 2023 19:55 UTC

pozz <pozzugno@gmail.com> writes:

> I have an array of structs. Its dimension is fixed:
>
> #define ARRAY_SIZE 200
> struct mystruct array[ARRAY_SIZE];
>
> This array is saved into a binary file with fwrite() and loaded in RAM at
> startup.
>
> During its run, the application could save a new entry in the array,
> starting from index 0. When the array is full, the new entry will be
> written to index 0 again, overwriting oldest entry. From this moment on,
> the number of entries in the array remains constant at ARRAY_SIZE.
>
> The application can be closed and restarted at any moment and, at startup,
> the last situation must be restored from the saved file.
>
> In order to understand what is the next position for the new entry, how
> many entries are stored in the array and so on, the struct has two members:
> a 16 bits unsigned integer ID and boolean valid flag.
>
> struct mystruct {
> bool valid;
> uint16_t id;
> struct myentry entry;
> }
>
> Initially the array is initialized with valid members to false.
>
> Now, I'm trying to write the startup function that, after loading the array
> from file to RAM, should detect what is the next entry position, how many
> entries are stored in the array and so on.

You are, fundamentally, storing the wrong data. Save the index of the
next entry as well as the array. And if you are using the IDs only to
find the next entry, remove the id member from the struct.

--
Ben.

Re: Detect wrap-around on array

<mDb2N.67508$rEF.31703@fx47.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30249&group=comp.lang.c#30249

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx47.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Detect wrap-around on array
Newsgroups: comp.lang.c
References: <uib6g7$dgtq$1@dont-email.me> <KI92N.39576$EUq9.7162@fx41.iad>
Lines: 36
Message-ID: <mDb2N.67508$rEF.31703@fx47.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Mon, 06 Nov 2023 20:02:26 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Mon, 06 Nov 2023 20:02:26 GMT
X-Received-Bytes: 1847
 by: Scott Lurndal - Mon, 6 Nov 2023 20:02 UTC

scott@slp53.sl.home (Scott Lurndal) writes:
>pozz <pozzugno@gmail.com> writes:
>>I have an array of structs. Its dimension is fixed:
>>
>> #define ARRAY_SIZE 200
>> struct mystruct array[ARRAY_SIZE];
>>
>>This array is saved into a binary file with fwrite() and loaded in RAM
>>at startup.
>>
>>During its run, the application could save a new entry in the array,
>>starting from index 0. When the array is full, the new entry will be
>>written to index 0 again, overwriting oldest entry. From this moment on,
>>the number of entries in the array remains constant at ARRAY_SIZE.
>
>Generally known as a ring buffer.
>
>https://en.wikipedia.org/wiki/Circular_buffer
>
>Which requires metadata (head and tail pointers, generally
>when the producer and consumer are distinct).
>
>Use 'mmap' instead of fwrite() [on posix systems] and include
>a fixed header before the ring buffer containing metadata
>like the head/tail pointers, capacity, etc.
>

A good description of how such a buffer works in a producer/consumer
environment is in the ARM SMMU specification:

IHI0070E_a-System_Memory_Management_Unit_Architecture_Specification.pdf

Which can be downloaded from the ARM website..

See section 3.5 on page 53.

Re: Detect wrap-around on array

<uibm83$kq5e$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30250&group=comp.lang.c#30250

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: pozzu...@gmail.com (pozz)
Newsgroups: comp.lang.c
Subject: Re: Detect wrap-around on array
Date: Mon, 6 Nov 2023 22:36:02 +0100
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <uibm83$kq5e$1@dont-email.me>
References: <uib6g7$dgtq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 6 Nov 2023 21:36:03 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0f69ecfa7a3f7311075baf05c819a73e";
logging-data="682158"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+HVe8pSYepmlV3vLlZd1iepNufbolDZV4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:LFzNKQRocL7oUHkZK29Il9ynYok=
Content-Language: it
In-Reply-To: <uib6g7$dgtq$1@dont-email.me>
 by: pozz - Mon, 6 Nov 2023 21:36 UTC

Il 06/11/2023 18:07, pozz ha scritto:
> I have an array of structs.
[...]

I oversimplified my problem. I don't really use fread/fwrite to
load/save the array to the disk. It isn't a disk at all, it's a NOR
Flash in an embedded application.

So the CPU can erase an entire sector (the array), transforming every
byte to 0xFF, or can write whatever value to a location previously erased.

My array is initialized to 0xFF by erasing the Flash sectors where it is
saved in non-volatile way. When a new entry is generated, the struct is
written to the Flash.

Re: Detect wrap-around on array

<uign8n$1ocsq$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30251&group=comp.lang.c#30251

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.nntp4.net!speedkom.net!fu-berlin.de!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nos...@please.ty (jak)
Newsgroups: comp.lang.c
Subject: Re: Detect wrap-around on array
Date: Wed, 8 Nov 2023 20:24:08 +0100
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <uign8n$1ocsq$1@dont-email.me>
References: <uib6g7$dgtq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 8 Nov 2023 19:24:08 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="80ebc3a2032550bcc1fd4384def569e6";
logging-data="1848218"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/j10UylnT8Lo8RtymSUiMi"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17.1
Cancel-Lock: sha1:6ie3V/cY1HxkcOFHY609Bww1Jbw=
In-Reply-To: <uib6g7$dgtq$1@dont-email.me>
 by: jak - Wed, 8 Nov 2023 19:24 UTC

pozz ha scritto:
> I have an array of structs. Its dimension is fixed:
>
>   #define ARRAY_SIZE            200
>   struct mystruct array[ARRAY_SIZE];
>
> This array is saved into a binary file with fwrite() and loaded in RAM
> at startup.
>
> During its run, the application could save a new entry in the array,
> starting from index 0. When the array is full, the new entry will be
> written to index 0 again, overwriting oldest entry. From this moment on,
> the number of entries in the array remains constant at ARRAY_SIZE.
>
> The application can be closed and restarted at any moment and, at
> startup, the last situation must be restored from the saved file.
>
> In order to understand what is the next position for the new entry, how
> many entries are stored in the array and so on, the struct has two
> members: a 16 bits unsigned integer ID and boolean valid flag.
>
>   struct mystruct {
>     bool valid;
>     uint16_t id;
>     struct myentry entry;
>   }
>
> Initially the array is initialized with valid members to false.
>
> Now, I'm trying to write the startup function that, after loading the
> array from file to RAM, should detect what is the next entry position,
> how many entries are stored in the array and so on.
>
> It's very simple if less than 65536 entries have been added to the
> array. It's sufficient to search the entry with the maximum ID.
> What happens if one more entry is added? The new entry ID will be zero,
> that is the lowest ID in the array, but it's the newest entry in the array.
>
> Any help? I suspect the solution is in the difference of unsigned integers.

Everything would become simple if you save data starting from the most
recent entry and respecting the circularity. In this way, when
restarting, the first field will also be the most recent. With a
circular beffer it is not important that the data are positioned exactly
as originally.

Re: Detect wrap-around on array

<uirf3b$7no3$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30261&group=comp.lang.c#30261

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: vir.camp...@invalid.invalid (Vir Campestris)
Newsgroups: comp.lang.c
Subject: Re: Detect wrap-around on array
Date: Sun, 12 Nov 2023 21:12:11 +0000
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <uirf3b$7no3$1@dont-email.me>
References: <uib6g7$dgtq$1@dont-email.me> <uibm83$kq5e$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 12 Nov 2023 21:12:11 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="12fc3fd05bfea8988f8ca6911032ad72";
logging-data="253699"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/BFH7Bu+V4NfGDfvc0/bdrCt6iOR0e64Y="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ebqpFPGCJ+GMwKASfUBu3DjXlD4=
In-Reply-To: <uibm83$kq5e$1@dont-email.me>
Content-Language: en-GB
 by: Vir Campestris - Sun, 12 Nov 2023 21:12 UTC

On 06/11/2023 21:36, pozz wrote:
> Il 06/11/2023 18:07, pozz ha scritto:
>> I have an array of structs.
> [...]
>
> I oversimplified my problem. I don't really use fread/fwrite to
> load/save the array to the disk. It isn't a disk at all, it's a NOR
> Flash in an embedded application.
>
> So the CPU can erase an entire sector (the array), transforming every
> byte to 0xFF, or can write whatever value to a location previously erased.
>
> My array is initialized to 0xFF by erasing the Flash sectors where it is
> saved in non-volatile way. When a new entry is generated, the struct is
> written to the Flash.
>
You might want to consider what would happen if the power went off after
you've erased the sector, but before you've written the new data.

Andy

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor