11/20/2015
GUIDs (collection of procedure)
v. 2.5.288.87
WinDev, WebDev and WinDev Mobile consulting
(empty)
Loading...

(2015-11-20) - GUIDs: When size DOES matter

GUIDs are extremely practical. By some advanced mathematical magic, they give you a unique identifier for anything you need. However, GUIDs are big: in pure binary form, they occupy 128bits (or 16 BYTES, if you prefer) of space, twice as big as any integer available (the biggest integer we can work with is on 8 bytes)…

So, as there is no type of numerical/binary variable available to store a GUID, we are usually working on them in HEXADECIMAL format, which means that we need 32 bytes to store a GUID. 

A GUID can also be displayed (and even stored) Formatted, in which case we need 38 bytes (the guid is displayed this way {c4f06b39-aa11-4383-a772-5de1a5e60130} instead of that way c4f06b39aa114383a7725de1a5e60130).

Of course, remember that if we store a GUID inside a UNICODE string, all these numbers are DOUBLED, as a unicode string store each character as TWO bytes.

Why do I talk about GUID size? I am using them extensively in my WXReplication system, which means that I often have several of them in EACH RECORD of my DBs. One for the record identifier and one for each of the linked records.

Clearly, this is not a big problem when we think of the size of hard drives, but it still matter when communication is involved. The bigger the data, the slower the exchanges, and the more costly too, when working with mobile apps and data plans.

So I decided to create collection of procedures to manage GUIDs in a slightly different way, and more specifically by encoding the GUID as a BASE64 string. In this case, a GUID can be stored in only 24 bytes, which is a 25% improvement.

This is a stepping stone for some changes in WXReplication (and WXEDM, of course) where I will soon replace all GUIDs fields currently 32 chars long in UNICODE = 64 bytes by ANSI fields on 24, thus saving 40 bytes each time.

The collection of procedures is called CPR_GUID and contains the following methods:
- GetGUID: new version overwriting the existing native function and now supporting also the cstguid64 constant to get directly a base64 encoded new GUID)
- GUIDRoughToBase64: Converts a hex coded guid into a base64 one
- GUIDBase64ToRough: converts a base64 coded guid into a hex coded one
- GUIDFormattedToRough: Convert a formatted guid into a rough one
- GUIDRoughToFormatted: convert a rough guid (hex based) into a formatted one.

So, log in, if not already done, download it, and enjoy.

-FREE-