For writing and reading gigabytes of data I want control at the byte level. Unfortunately I find it extremely difficult to make sense of raw byte access with the available documentation and resources.
What I'd like to get running is a Swift 3 equivalent of the following C code
#include <stdlib.h>
#include <stdio.h>
int main() {
int N=300;
size_t bufsz = N*sizeof(uint8_t) + N*sizeof(double);
uint8_t *buffer = malloc(bufsz);
size_t ofs=0;
while (ofs<bufsz) {
*(buffer+ofs) = 'A';
ofs += sizeof(uint8_t);
*((double*)(buffer+ofs)) = 6.0138242189890428e-154;
ofs += sizeof(double);
}
FILE *file = fopen("foo.bin", "w");
fwrite(buffer, bufsz, sizeof(uint8_t), file);
fclose(file);
}
How does this translate to Swift?