Module import failing after $ dub add mypackage

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jul 16 17:31:43 UTC 2021


On Fri, Jul 16, 2021 at 04:54:18PM +0000, Scotpip via Digitalmars-d-learn wrote:
[...]
> I simply need a fast binary serialisation lib to read and write a
> large list of structs to local disk - it's not for inter-app
> communication. The struct is simple and only contains primitive D data
> types. If you are aware of any package that would be a better bet I'd
> appreciate your advice. Or is there a more direct way to dump a list
> from memory to disk and read it back again?  This is the kind of
> low-level stuff that's rather new to me...

If your struct contains only POD types (no indirections), and you do not
need to share it across machines, then you could just write the raw
bytes to disk and read them back:

	struct Data { ... }

	// To write:
	File myFile = ...;
	// write number of items to disk somewhere
	foreach (Data item; myList) {
		myFile.rawWrite((&item)[0 .. 1]);
	}

	// To read:
	File myFile = ...;
	int numItems = /* read number of items from disk somewhere */;
	foreach (i; 0 .. numItems) {
		Data item;
		myFile.rawRead((&item)[0 .. 1]);
		appendToList(item);
	}

If your data is in an array, it's even easier:

	Data[] myData;
	// write myData.length to disk somewhere
	myFile.rawWrite(myData);

	myData.length = /* read number of items from disk */;
	myFile.rawRead(myData);

Note that the above only works if your data contains no indirections.
(Beware that strings *do* contain indirection unless you're using
fixed-length buffers.)  If there are indirections you'll need to do
something smarter.


T

-- 
The irony is that Bill Gates claims to be making a stable operating system and Linus Torvalds claims to be trying to take over the world. -- Anonymous


More information about the Digitalmars-d-learn mailing list