So far, I've used stdio functions with standard buffers, namely char arrays. But in doing a b-tree project, the sample
provided used fileio.h. Since I was not familiar with that & don't know where to get, I converted I/O statements to the stdio
equivalents. The sample had code to read in data from file to a btree page structure. I used the stdio fread to do the
equivalent. I know that fread() uses a void type buffer, but is it best to use std type buffers like char? Here's what I
mean:
the converted code goes like this:
Notice that a btree page structure is passed to fread as the buffer to read in pagesize bytes. My question is does thisCode:typedef struct { short keycount; // # keys in page char key[MAXKEYS][7]; // the actual keys, a key is 6 chars long short kyrrn[MAXKEYS]; // ptrs to rrns of the key data records short child[MAXKEYS+1]; // ptrs to rrns of descendants } BTPAGE; #define PAGESIZE sizeof(BTPAGE) int btread(short rrn, BTPAGE *page_ptr) { long addr; addr = (long)rrn * (long)PAGESIZE + 2L; fseek(btfd, addr, 0); return ( fread(page_ptr, PAGESIZE, 1, btfd) ); }
method work as I intended? I'm not sure when testing the code & I've never done btrees file-based, only done memory-based.
I mean does using the code like above write a btree page structure to file in orderly fashion in order of keycount 1st, then
keys, then rrns, last child ptr rrns & read it back to memory as a btree page structure, storing the values correctly, in the
right place?
Or am I better off converting the btree page structure contents into characters to be dumped in a char buffer equivalent to
size of btree page & then do read/writes with that to file. using this method I think I can better visualize & analyze the
content & structure in file & memory.



LinkBack URL
About LinkBacks



Show some more code if you want help with it.