Solved

Declaring arrays

Posted on 1998-08-21
7
247 Views
Last Modified: 2012-05-04
Hi,

I have been declaring my array in the fashion shown in the code segment below and the max size for my PC is 64x64. What's wrong with my codes? How can I increase the sizes of the arrays to 512x512? Do I have to deal with setting the buffer size or virtual memory?

My declaration of array is as follow:

#define HEIGHT 32
#define WIDTH 32

  short  x,y,ro[HEIGHT][WIDTH],go[HEIGHT][WIDTH],bo[HEIGHT][WIDTH];
  short  rq[HEIGHT][WIDTH],gq[HEIGHT][WIDTH],bq[HEIGHT][WIDTH];
  float  rn[HEIGHT][WIDTH],gn[HEIGHT][WIDTH],bn[HEIGHT][WIDTH];
  float  rq2[HEIGHT][WIDTH],gq2[HEIGHT][WIDTH],bq2[HEIGHT][WIDTH];


The way I use the array :

  for (x=0;x<HEIGHT;x++)
     {
       for (y=0;y<WIDTH;y++)
          {
              Infile>>ro[x][y]>>go[x][y]>>bo[x][y];

              rn[x][y]=ro[x][y]/255.0;
              gn[x][y]=go[x][y]/255.0;
              bn[x][y]=bo[x][y]/255.0;

              rq[x][y]=ro[x][y]*15/255;
              gq[x][y]=go[x][y]*15/255;
              bq[x][y]=bo[x][y]*15/255;

              rq2[x][y]=rq[x][y]/15.0;
              gq2[x][y]=gq[x][y]/15.0;
            bq2[x][y]=bq[x][y]/15.0;

       }
  }

Can I have an example of more efficient implementation of arrays ?
0
Comment
Question by:peiyoke
  • 5
  • 2
7 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1170909
answer coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1170910
The way you have it declared now each array is 32X32 elements or a 1024 = 1K of elements  (not 1 k in size, 1 K of elements)  You have 6 arrays of shorts and 6 arrays of floats.
The size of each short array is 1024 elements times 2 bytes per element equals 2K.  The size of each float array is 1024 elements times 4 bytes per element equals 4 K.  All told you then have 36 K in arrays.

If you are running in a DOS program with a single 64K data segment, that means you arrays alone are over half of your aloted storage space.  And that is at 32X32.  512X512 arrays use 256 times the amount of memory.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1170911
One option is to move to a 32 bit programming environment where you not be limited to 64 K segments.  However, even there your 512X512 arrays would be considered excessive.  (They are about 9 meg)

If you are programming in DOS, you can use a memory model that has multiple data segments, but even then your individual arrays will be limited to 64K so you will never get close to 512X512.

It might be worth reconsidering your program design.  Do you really have to use these huge arrays?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:peiyoke
ID: 1170912
netiod,

I am very new in programming. By moving to the 32 environment, what changes should I implement on my codes? I do really need a 512x512 array.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1170913
Unless your code makes some "non-portable" assumptions, like assumes that integers have a particular size, or that pointers have a particular size and/or format, there will be no changes you need to make.  You just need to compile the code for a 32 compiler and run it under a 32 bit OS.  Assuming you are runing window 95, 98 or NT, you can use MS VC, Borland C++, or Borland Builder to create 32 bit console programs.  These are 32 bit programs that seem to the user to be DOS programs because they run at the DOS prompt.  They seem to the programmer to be standard C++ programs (they can do I/O to the console--which a regular windows program cannot).  However, unlike a DOS program, they use 32 bit memory addressing.  Any standard C++ program (one that doesn't OS specific/hardware specific code) will compile as a win32 console program with no changes.

Under win32 each array will be 1 meg.  That will work, but that is excessive even for a 32 program.  I suspect you can avoid that.  What are you trying to do?
0
 

Author Comment

by:peiyoke
ID: 1170914


I am using Turbo C++ compiler in Windows 95. I guess Turbo C++ that I am currently using is not a 32 bit program. I am trying to read data from colour image, one pixel with 3 colour components of one byte each, one image of size 512X512 pixels. Any idea on how to solve this?

Thanx.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1170915
You probably don't have to store all the pixels in memory at the same time.

The other option is to remain a DOS program but use a DOS extender to be able to access higher memory.  That is likely to be a pain however, and seeing as the PC world has moved to true 32 bit programming, doesn't make a lot of sense

A student edition of Borland C++ builder is like $80 and can produce 16 bit DOS, 16 bit windows, 32 bit console and 32 bit windows programs.  You might want to invest in it.  I prefer MS VC, but it is more expensive and only produces 32 console and 32 bit programs.  However its on-line help and debuger are both 1000nds of times better than builder's, for a beginner that is an important consideration...
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now