Solved

Declaring arrays

Posted on 1998-08-21
7
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

636 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