473,513 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about globals

mikejfe
12 New Member
Hi all. I have a question that is probably simple to answer, but I don't even know where to get started (i.e. for searching old posts, Google, etc.)

I am writing a program that reads in a 3 dimensional array text file. Then x, y, and z coordinate values are assigned to each value of the 3d array. These four arrays (3d array, x, y, z) get used in quite a few functions of my program. So, I define them all as globals.

My program needs to handle 3d arrays that could potentially be larger than 512x512x512, but my program doesn't know how large until the user inputs that information. I don't really want to hard code in some generic, large number when I create the arrays.

My question is then this: Is there anyway to have these four arrays be treated as globals, but created (with the proper size) after the user enters the size of the 3d array?

This piece of code is something I've done before, but of course sphere[i][j][k] isn't a global...
Expand|Select|Wrap|Line Numbers
  1. void LoadFile()
  2. {
  3.   int ***sphere = NULL;
  4.   sphere = new int**[userValueX];
  5.   for (i=0; i<userValueX; i++)
  6.     {
  7.        sphere[i] = new int*[userValueY];
  8.        for (j=0; j<userValueY; j++)
  9.          {
  10.             sphere[i][j] = new int[userValueZ];
  11.          }
  12.     }
  13. ...
  14. }
  15.  
Thanks in advance,
-Michael
Feb 11 '07 #1
1 1234
RRick
463 Recognized Expert Contributor
You've got the right idea for creating the arrays. Since you don't know their size, they will have to be created on the fly in your program. The way to make the variable global, is to move the definition outside of the subroutine. Move the defintion of sphere to above the sub definition.

If you want to reference the variable outside of this file, use: extern int ***sphere.

If you know they are only used with in the file they were defined, then preceed the definition with static. That limits their use to only this file.

A common technique is to begin global/static variables with something unique (ie. g_) for easy identification. Since I hate '_', I capitalize the first letter of the variable.
Feb 12 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1592
by: Stormkid | last post by:
Hi Group, I'm trying to use the longitude and latitude to do a radius search but I'm getting some inaccurate results, below is the code and I was wondering if anyone knows weather or not I'm doing the calculations any feed back is much appreciated. Thanks Todd class RadiusAssistant { var $maxLat; var $minLat;
5
2824
by: Frostillicus | last post by:
I'm trying to use array_multisort to sort by one of the dimensions of an array stored in $GLOBALS like this: array_multisort($GLOBALS, SORT_STRING, SORT_DESC); Each "row" in $GLOBALS contains a value for 'href', 'desc', and 'info' but when I try to pass one of these "columns" to array_multisort() it whinges about it not being an array or...
2
1733
by: asdfkajsdflkjsadlfkjoewqifoeiwjf | last post by:
Hi Im using php to parse an xml file of below format. I have no problem extracting the various values within the tags (lib, id, url, file etc), but cant get hold of whats in the tag (max_page, page etc) nor whats whithin the , , tags ... Can you suggest a generic parser and how to grab these or any other tips on what Im missing here :/
2
1534
by: Robin Munn | last post by:
OK, here's another software design question, one that's been bugging me for a while now. What do y'all think is the best way to handle program-level globals, such as configuration option -- especially in multi-module programs? Here's one approach: --- main.py --- import my_globals as g import somefuncs
18
1371
by: fred.dixon | last post by:
i have read the book and searched the group too ---------------------------------------------- im not gettin it. i want to read a global (OPTIONS) from file1 from a class method (func1) in file2 i want to understand how this works. ---------------------------------------------- #file1.py
4
2142
by: =?ISO-8859-1?Q?Gregory_Pi=F1ero?= | last post by:
I'm curious why this code isn't working how I expect it to: import sys d=3 def func1(a,b,c): print a,b,c,d print sys.path exec "func1(1,2,3)" in {'func1':func1}
4
4182
by: Fawzib Rojas | last post by:
I have an app with a WebBrowser component and I'm setting the the ObjectForScripting component so the object can be used from javascript. The object has a Scripting.Dictionary property. My problem is that in javascript I have to use "external.dictionary.Item('x')" to get the items instead of "external.dictionary('x')". If I create the...
1
1841
by: cokofreedom | last post by:
if __name__ == '__main__': print "Globals (For Loop):" try: for i in globals(): print "\t%s" % i except RuntimeError: print "Only some globals() printed\n" else: print "All globals() printed\n"
9
989
by: Pat | last post by:
I have a Globals class. In it, I have a variable defined something like this: remote_device_enabled = bool In one module, I assign True/False to Globals.remote_device_enabled. Once set, this value never changes. In another module, at the top after the imports statements, I tried this:
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7397
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7565
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5103
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4759
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3255
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
473
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.