Hi,
I have a bit of code for DOS written in borland C 4.5. I was receiving a error message about having to many globals.
There did seem to be quite a lot so I moved them all into a structure which I then allocated memory to in the function.
I believed at the time that the structure wouldn't require memory until a variable of it's type had been defined (at which point a pointer to memory space using malloc could be enacted).
However I have found that I am now using more global memory than before. How is this possible?
Here is a rough idea of the code format:
in codea.h
struct descriptors{
type variable1;
type variable2;
type variable3;
etc...
};
in codea.c
functionx{
struct descriptors *mem_descriptors_ptr;
struct descriptors desc_var;
mem_descriptors_ptr = (struct descriptors_struct *)malloc(sizeof(desc_var));
if (mem_descriptors_ptr == NULL)
error = set_error("Out Of Memory Loading 24CONF DESCRIPTORS- Fatal Error\n\r");
//calling a function sending structure
error = functiony(&desc_var);
}
functiony(struct descriptors *desc_var){
desc_var->variable1 = 1;
}
Can anyone see anything wrong with this?
Please help
Will
I have a bit of code for DOS written in borland C 4.5. I was receiving a error message about having to many globals.
There did seem to be quite a lot so I moved them all into a structure which I then allocated memory to in the function.
I believed at the time that the structure wouldn't require memory until a variable of it's type had been defined (at which point a pointer to memory space using malloc could be enacted).
However I have found that I am now using more global memory than before. How is this possible?
Here is a rough idea of the code format:
in codea.h
struct descriptors{
type variable1;
type variable2;
type variable3;
etc...
};
in codea.c
functionx{
struct descriptors *mem_descriptors_ptr;
struct descriptors desc_var;
mem_descriptors_ptr = (struct descriptors_struct *)malloc(sizeof(desc_var));
if (mem_descriptors_ptr == NULL)
error = set_error("Out Of Memory Loading 24CONF DESCRIPTORS- Fatal Error\n\r");
//calling a function sending structure
error = functiony(&desc_var);
}
functiony(struct descriptors *desc_var){
desc_var->variable1 = 1;
}
Can anyone see anything wrong with this?
Please help
Will