Thursday, May 19, 2011

specificity

On a whim I once again re-wrote some of my file reader. This time I'm making a library of functions that do specific things. I have one function finished and another half-started.

The first function scans through a file and reports back how many timestamps there are for a specific unit on a specific channel. You pass the function a string (the filename), a channel, and a unit. With this data I want to then allocate some memory to hold an array of all the timestamps for that unit/channel.

The second function will actually pass the timestamps to that allocated memory.

I can't decide if the first function should just report back the number of timestamps or if it should just go ahead and report back the number of bytes that need to be allocated. There are benefits to both methods.

Why allocate on the fly? Each timestamp is a long integer. There might be a dozen in a file or there might be several hundred thousand. This seems prime for learning me some malloc.

So this library would be used with all the different data types in the file eventually and would be used as follows:

1) Call the function that determines how big the data is in the file for that channel/unit, or digitized waveform channel, or event.

2) Allocate space for the data.

3) Call the function to get the data (passing it a pointer to the space allocated as well as the channel/unit/filename/etc).

This won't be too particularly useful in real life but it is good practice for making a program that does specific things instead of a kitchen sink program that I hand-modify every time I need it to do something else.

Practice is practice.

No comments:

Post a Comment