Cancelled

C++ project

I have an application that takes a pointer to a function and returns the result of the function. I need to read the function in memory, save it as a file (as binary data is fine), and then read it in later, so that it can run it again.

The 2 functions are:

1. Save function from memory

2. Load function from text file

The specs are:

typedef void (* FUNCTION_PTR) (float*, float**);

int saveFunction (FUNCTION_PTR pToFunction, CString fileName)

// this function takes the pointer to the function in memory and saves it as a file

FUNCTION_PTR LoadFunction (CString fileName)

// this function takes the filename, loads the file, loads the function into memory, and then returns a pointer to the funciton

to run the function:

(*pToFunction)(inputData, output);

// This is how it works. I just added to explain.

the function should occupy less than 10K of memory.

here is an example of a function that we want to save and load the binary code for:

#define TRUNC(x)(((x)>=0) ? floor(x) : ceil(x))

#define C_FPREM (_finite(f[0]/f[1]) ? f[0]-(TRUNC(f[0]/f[1])*f[1]) : f[0]/f[1])

#define C_F2XM1 (((fabs(f[0])<=1) && (!_isnan(f[0]))) ? (pow(2,f[0])-1) : ((!_finite(f[0]) && !_isnan(f[0]) && (f[0]<0)) ? -1 : f[0]))

float DiscipulusCFunction(float v[])

{

long double f[8];

long double tmp = 0;

int cflag = 0;

f[0]=f[1]=f[2]=f[3]=f[4]=f[5]=f[6]=f[7]=0;

f[0]-=v[60];

cflag=(f[0] < f[2]);

f[1]+=f[0];

f[0]+=v[31];

f[0]+=f[2];

if (!cflag) f[0] = f[2];

f[0]-=v[12];

f[0]/=f[0];

if (cflag) f[0] = f[0];

if (!cflag) f[0] = f[3];

f[0]+=f[1];

f[0]/=f[3];

f[0]/=v[61];

f[0]/=v[10];

cflag=(f[0] < f[1]);

f[0]+=f[1];

cflag=(f[0] < f[2]);

cflag=(f[0] < f[0]);

f[0]+=f[0];

if (!_finite(f[0])) f[0]=0;

return f[0];

}

the first parameter that is passed is an array of inputs to function. it is an array of 64 floats.

the second parameter is the output from the function. it says return f[0], but i call it with this code:

(*pGeneticProgram)(g_StockData[currentDay], Outputs);

myValue = Outputs[0];

so, i am not using the return value. it stores the return values in Outputs. I don't know why the function code only has one parameter. i guess that's not correct because i know the code i call it works. so i think it actually takes 2 parameters, the input array[64], and the output array[8].

if its easier to use the return value instead of modifying the outputs array, that's could work. but i don't know if that works so if you want to do it let me know and i will try it and see.

also, there can be up to 2048 operations. (f[0]-=v[60]; is 1 operation). so i think that means the function could take up to 8k of memory, but i am not sure.

you can call me to ask questions at 310 709 2042 (usa). i am available from 5AM to 11PM everyday (including new years day).

feel free to ask me questions by email or call me.

also, the outputs array has 8 floats.

if possible, let's save the data as a text file. if not, it can be saved as a binary file.

Skills: C Programming

See more: why binary, project work example, int v, int i, use binary, code binary, binary work, read example, binary text, binary t, value stores, void, text inputs, pow, memory c, it operations, int, free project, float, code c, c guess, project input output, file binary, file load save, void input data

About the Employer:
( 121 reviews ) Belfast, Ireland

Project ID: #210584