Solved

Declaring arrays

Posted on 1998-08-21
7
248 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ - Convert a wString to char * 9 515
How to split this in C++ 4 94
c++ reading data from file into two dimensional array 3 96
Beginner to Unreal Engine 4 5 61
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

920 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

16 Experts available now in Live!

Get 1:1 Help Now