Build program with data from file

Build program with data from file

I am planning to create a program that will use a big array of constant data when it executes. The obvious thing to do is read the data from a file, but I'm wondering if there is a way to read the data in during the compilation and store it with the executable code. Obviously this could be achieved by a DATA statement, but for a big multidimensional array it is a bit cumbersome. I'm pretty sure the answer is that there is no alternative to the DATA statement, but maybe there is something I don't know about.

6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Quoting - gib
I am planning to create a program that will use a big array of constant data when it executes. The obvious thing to do is read the data from a file, but I'm wondering if there is a way to read the data in during the compilation and store it with the executable code. Obviously this could be achieved by a DATA statement, but for a big multidimensional array it is a bit cumbersome.

Put the DATA statement in an INCLUDE file?

Quoting - tim18

Quoting - gib
I am planning to create a program that will use a big array of constant data when it executes. The obvious thing to do is read the data from a file, but I'm wondering if there is a way to read the data in during the compilation and store it with the executable code. Obviously this could be achieved by a DATA statement, but for a big multidimensional array it is a bit cumbersome.

Put the DATA statement in an INCLUDE file?

It's generating the DATA statement that I was hoping to avoid. A vain hope, obviously, but it isn't a big deal anyway.

Quoting - gib

It's generating the DATA statement that I was hoping to avoid. A vain hope, obviously, but it isn't a big deal anyway.

If you are only running on Windows then a user defined resource may suit. The data can be pulled from a file at (resource) compile time, which is then bound into the executable or DLL (as per other resources such as dialog templates or strings). At run time you then use Windows API functions such as FindResource and LoadResource, possibly in combination with the C_F_POINTER procedure from ISO_C_BINDING, to make the data available to the program.

I have used this approach to bind a default configuration file into an executable.

The online documentation for the resource compiler (rc.exe) has more information.

IanH

Quoting - IanH

If you are only running on Windows then a user defined resource may suit. The data can be pulled from a file at (resource) compile time, which is then bound into the executable or DLL (as per other resources such as dialog templates or strings). At run time you then use Windows API functions such as FindResource and LoadResource, possibly in combination with the C_F_POINTER procedure from ISO_C_BINDING, to make the data available to the program.

I have used this approach to bind a default configuration file into an executable.

The online documentation for the resource compiler (rc.exe) has more information.

IanH

Ah, thanks Ian, that's the sort of thing I was looking for. Unfortunately I'd like to run this on other platforms besides Windows. It seems I'll have to write a little program to create the DATA statement.

You could potentially use Excel to generate the data satatments

1.2 3.4 5.6 ...
9.8 7.6 5.4 ...
.
.
.

Insertcolumns at left and at right

'DATA Array('1 ':' 10 ') /' 1.2 3.4 5.6 ... '/'
'DATA Array('+R-1C+10 ':' +R-1C+10 ') /' 1.2 3.4 5.6 ... '/'

Or write a program to convert the data to an includ file.

Use the Excel method for a once only situation
Use the program method should you want to create multiple tables or tweek the table later.

Jim Dempsey

www.quickthreadprogramming.com

Leave a Comment

Please sign in to add a comment. Not a member? Join today