Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Special Data Type Declaration and Usage (http://www.velocityreviews.com/forums/t805961-special-data-type-declaration-and-usage.html)

Mike Copeland 11-15-2011 09:04 PM

Special Data Type Declaration and Usage
 
I need to declare an enormous array (100,000 members) of a small
scalar object, and I want to populate it with default values and change
some of them as needed throughout the processing. The range of distinct
values for each element is 0-15, so I could use a 4 bit "mini-byte" if
something like that existed.
My question is: can I declare a bit structure data type and use it
this way? If that's possible, I don't know how to do so, nor how I'd
manipulate the data values in it. Please advise. TIA

Ian Collins 11-15-2011 09:09 PM

Re: Special Data Type Declaration and Usage
 
On 11/16/11 10:04 AM, Mike Copeland wrote:
> I need to declare an enormous array (100,000 members) of a small
> scalar object, and I want to populate it with default values and change
> some of them as needed throughout the processing. The range of distinct
> values for each element is 0-15, so I could use a 4 bit "mini-byte" if
> something like that existed.
> My question is: can I declare a bit structure data type and use it
> this way? If that's possible, I don't know how to do so, nor how I'd
> manipulate the data values in it. Please advise. TIA


You can't have a single type smaller than a char. You could put a pair
of your "mini-byes" in a bit-field.

--
Ian Collins

Gennaro Prota 11-15-2011 09:16 PM

Re: Special Data Type Declaration and Usage
 
On Tue, 15 Nov 2011 22:04:25 +0100, Mike Copeland <mrc2323@cox.net> wrote:

> I need to declare an enormous array (100,000 members) of a small
> scalar object, and I want to populate it with default values and change
> some of them as needed throughout the processing. The range of distinct
> values for each element is 0-15, so I could use a 4 bit "mini-byte" if
> something like that existed.
> My question is: can I declare a bit structure data type and use it
> this way? If that's possible, I don't know how to do so, nor how I'd
> manipulate the data values in it. Please advise. TIA


Are you sure that the array is "enormous"? Using one (whole!) byte per
element it would occupy less than 100KiB.

--
Gennaro Prota | name.surname gmail.com
Breeze C++ (preview): <http://sourceforge.net/projects/breeze/>
Do you need expertise in C++? I'm available.

Mike Copeland 11-15-2011 09:30 PM

Re: Special Data Type Declaration and Usage
 
In article <op.v40apype4vph3f@gp.homenet.telecomitalia.it>,
gennaro.prota+Usenet@gmail.com says...
> On Tue, 15 Nov 2011 22:04:25 +0100, Mike Copeland <mrc2323@cox.net> wrote:
>
> > I need to declare an enormous array (100,000 members) of a small
> > scalar object, and I want to populate it with default values and change
> > some of them as needed throughout the processing. The range of distinct
> > values for each element is 0-15, so I could use a 4 bit "mini-byte" if
> > something like that existed.
> > My question is: can I declare a bit structure data type and use it
> > this way? If that's possible, I don't know how to do so, nor how I'd
> > manipulate the data values in it. Please advise. TIA

>
> Are you sure that the array is "enormous"? Using one (whole!) byte per
> element it would occupy less than 100KiB.
>

It's "enormous" to me, as I have many other large data structures in
this program, and I have to declare it globally (it's accessed from a
number of subprograms in several source files). My concern is Heap
allocation, inasmuch as there must be _some_ limit as to how much
program data can be declared before the program chokes. I;m using
VS6.0, and I don't know what that limit is.
I was hoping that I could cut down the total size of this data
component and still process it efficiently. It seems not possible...
8<{{

Ian Collins 11-15-2011 09:36 PM

Re: Special Data Type Declaration and Usage
 
On 11/16/11 10:30 AM, Mike Copeland wrote:
> In article<op.v40apype4vph3f@gp.homenet.telecomitalia .it>,
> gennaro.prota+Usenet@gmail.com says...
>> On Tue, 15 Nov 2011 22:04:25 +0100, Mike Copeland<mrc2323@cox.net> wrote:
>>
>>> I need to declare an enormous array (100,000 members) of a small
>>> scalar object, and I want to populate it with default values and change
>>> some of them as needed throughout the processing. The range of distinct
>>> values for each element is 0-15, so I could use a 4 bit "mini-byte" if
>>> something like that existed.
>>> My question is: can I declare a bit structure data type and use it
>>> this way? If that's possible, I don't know how to do so, nor how I'd
>>> manipulate the data values in it. Please advise. TIA

>>
>> Are you sure that the array is "enormous"? Using one (whole!) byte per
>> element it would occupy less than 100KiB.
>>

> It's "enormous" to me, as I have many other large data structures in
> this program, and I have to declare it globally (it's accessed from a
> number of subprograms in several source files). My concern is Heap
> allocation, inasmuch as there must be _some_ limit as to how much
> program data can be declared before the program chokes.


That depends on the configuration (physical and OS) of the target system.

> I;m using VS6.0, and I don't know what that limit is.


Stop right there! An obsolete, non-standard and buggy compiler? I'm
sure you can do better than that.

> I was hoping that I could cut down the total size of this data
> component and still process it efficiently. It seems not possible...
> 8<{{


Yes you could cut down the size, but that is often orthogonal to
efficient processing.

--
Ian Collins

Mike Copeland 11-15-2011 10:02 PM

Re: Special Data Type Declaration and Usage
 
In article <9ig4bcFi5oU7@mid.individual.net>, ian-news@hotmail.com
says...
> On 11/16/11 10:30 AM, Mike Copeland wrote:
> > In article<op.v40apype4vph3f@gp.homenet.telecomitalia .it>,
> > gennaro.prota+Usenet@gmail.com says...
> >> On Tue, 15 Nov 2011 22:04:25 +0100, Mike Copeland<mrc2323@cox.net> wrote:
> >>

> > It's "enormous" to me, as I have many other large data structures in
> > this program, and I have to declare it globally (it's accessed from a
> > number of subprograms in several source files). My concern is Heap
> > allocation, inasmuch as there must be _some_ limit as to how much
> > program data can be declared before the program chokes.

>
> That depends on the configuration (physical and OS) of the target system.
>
> > I'm using VS6.0, and I don't know what that limit is.

>
> Stop right there! An obsolete, non-standard and buggy compiler? I'm
> sure you can do better than that.


<sigh...> Yes, I hear that all the time I reveal that. However, I'm
an (old) independent developer with limited resources...and 6.0 is all I
possess. I know there there are various Express versions available for
no cost, but the effort to convert to one (with STL, MFC, etc.
limitations that might be overwhelming) is too daunting to start at my
age (72).
VS6.0 works for me, and I have only one client. Thus, for many
reasons I don't need to be - nor wish to be - competitive. That may
seem to be heresy to most here, but I don't have the time or energy to
"keep up" with you guys...8<{{

> > I was hoping that I could cut down the total size of this data
> > component and still process it efficiently. It seems not possible...
> > 8<{{

>
> Yes you could cut down the size, but that is often orthogonal to
> efficient processing.
>

Yes, I see, and I appreciate that thought. This was one of my
concerns.

Brian Drummond 11-15-2011 10:17 PM

Re: Special Data Type Declaration and Usage
 
On Tue, 15 Nov 2011 14:04:25 -0700, Mike Copeland wrote:

> I need to declare an enormous array (100,000 members) of a small scalar
> object, and I want to populate it with default values and change some of
> them as needed throughout the processing. The range of distinct values
> for each element is 0-15, so I could use a 4 bit "mini-byte" if
> something like that existed.
> My question is: can I declare a bit structure data type and use it
> this way? If that's possible, I don't know how to do so, nor how I'd
> manipulate the data values in it. Please advise. TIA


Dead easy.

type Element is range 0 .. 15;
constant Default_Element : Element := 1;
For Element'size use 4;
type Element_Array is array (range 1 .. 100000) of Element
:= (others => Default_Element);

oops, this is comp.lang.c++. Sorry.

- Brian

Jorgen Grahn 11-15-2011 10:19 PM

Re: Special Data Type Declaration and Usage
 
On Tue, 2011-11-15, Mike Copeland wrote:
> I need to declare an enormous array (100,000 members) of a small
> scalar object, and I want to populate it with default values and change
> some of them as needed throughout the processing.


Why does it have to be an array? It would be easier to handle this if
you could create a class MyBundleOf100000SmallThings and use one of
those. Internally you may pack them into a std::vector<unsigned char>
or something. You won't easily be able to say

enormous[4711] = 2;

though, although you can easily /read/ from it using that syntax.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Ian Collins 11-15-2011 10:51 PM

Re: Special Data Type Declaration and Usage
 
On 11/16/11 11:19 AM, Jorgen Grahn wrote:
> On Tue, 2011-11-15, Mike Copeland wrote:
>> I need to declare an enormous array (100,000 members) of a small
>> scalar object, and I want to populate it with default values and change
>> some of them as needed throughout the processing.

>
> Why does it have to be an array? It would be easier to handle this if
> you could create a class MyBundleOf100000SmallThings and use one of
> those. Internally you may pack them into a std::vector<unsigned char>
> or something. You won't easily be able to say
>
> enormous[4711] = 2;
>
> though, although you can easily /read/ from it using that syntax.


Both operators are possible through the use of a simple proxy object.

--
Ian Collins

Gennaro Prota 11-15-2011 10:58 PM

Re: Special Data Type Declaration and Usage
 
On Tue, 15 Nov 2011 22:30:03 +0100, Mike Copeland <mrc2323@cox.net> wrote:

> In article <op.v40apype4vph3f@gp.homenet.telecomitalia.it>,
> gennaro.prota+Usenet@gmail.com says...
>> On Tue, 15 Nov 2011 22:04:25 +0100, Mike Copeland <mrc2323@cox.net>
>> wrote:
>>
>> > I need to declare an enormous array (100,000 members) of a small
>> > scalar object, and I want to populate it with default values and

>> change
>> > some of them as needed throughout the processing. The range of

>> distinct
>> > values for each element is 0-15, so I could use a 4 bit "mini-byte" if
>> > something like that existed.
>> > My question is: can I declare a bit structure data type and use it
>> > this way? If that's possible, I don't know how to do so, nor how I'd
>> > manipulate the data values in it. Please advise. TIA

>>
>> Are you sure that the array is "enormous"? Using one (whole!) byte per
>> element it would occupy less than 100KiB.
>>

> It's "enormous" to me, as I have many other large data structures in
> this program, and I have to declare it globally (it's accessed from a
> number of subprograms in several source files). My concern is Heap
> allocation, inasmuch as there must be _some_ limit as to how much
> program data can be declared before the program chokes. I;m using
> VS6.0, and I don't know what that limit is.
> I was hoping that I could cut down the total size of this data
> component and still process it efficiently. It seems not possible...
> 8<{{


It's possible but my advice is "don't do it yet". It seems a premature
optimization concern. Wrap a simple

typedef unsigned char byte ; // guaranteed to hold at least [0..255]
std::vector< byte > v ;

into a class of your own, which you can change later (if needed) to use
a packed representation.

--
Gennaro Prota | name.surname gmail.com
Breeze C++ (preview): <http://sourceforge.net/projects/breeze/>
Do you need expertise in C++? I'm available.


All times are GMT. The time now is 12:39 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.