Inside of my program I am trying to define an array of floats that are very globally accessible within the program. These are just for development purposes so I am trying to achieve this array using the fewest amount of code changes.
I do realize that this is VERY bad programming practice and style but I am on a single developer project and this code will only be there for a day or two on a separate branch of the codebase.
The array needs to be accessed from 2 parts of a very large codebase and I dont have a lot of ways for these two sections to communicate with each-other without a lot of issues.
I am considering two designs:
globalTweakingArray.h
v1
#define TWEAKING_ELEMENTS
float tweakingArray[TWEAKING_ELEMENTS];
v2
#define TWEAKING_ELEMENTS
float *tweakingArray;
// Where can I malloc this
Now my confusion comes from how these are used, what address space they are in etc etc. The goal would be that within a-couple c++ source files they can #import "globalTweakingArray.h"
and all be reading and writing the same values.
I am a bit confused about the implications of global variables here so I am not certain what dangers come with the design of v1
and v2
. Furthermore I am not even sure how I can malloc some space for the array in v2
.
Are either of these designs the correct way to define a global array? What are the dangers that come with either? Are they even the correct way to define this global tweaking array?
Side-Note: One of the places I will be accessing this array from is objective-c source. That shouldn't matter right? A float is a float and a pointer is a pointer right?