Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #11483 > unrolled thread

Special Data Type Declaration and Usage

Started bymrc2323@cox.net (Mike Copeland)
First post2011-11-15 14:04 -0700
Last post2011-11-15 16:28 -0600
Articles 16 — 8 participants

Back to article view | Back to comp.lang.c++


Contents

  Special Data Type Declaration and Usage mrc2323@cox.net (Mike Copeland) - 2011-11-15 14:04 -0700
    Re: Special Data Type Declaration and Usage Ian Collins <ian-news@hotmail.com> - 2011-11-16 10:09 +1300
    Re: Special Data Type Declaration and Usage "Gennaro Prota" <gennaro.prota+Usenet@gmail.com> - 2011-11-15 22:16 +0100
      Re: Special Data Type Declaration and Usage mrc2323@cox.net (Mike Copeland) - 2011-11-15 14:30 -0700
        Re: Special Data Type Declaration and Usage Ian Collins <ian-news@hotmail.com> - 2011-11-16 10:36 +1300
          Re: Special Data Type Declaration and Usage mrc2323@cox.net (Mike Copeland) - 2011-11-15 15:02 -0700
            Re: Special Data Type Declaration and Usage Victor Bazarov <v.bazarov@comcast.invalid> - 2011-11-15 18:10 -0500
        Re: Special Data Type Declaration and Usage "Gennaro Prota" <gennaro.prota+Usenet@gmail.com> - 2011-11-15 23:58 +0100
        Re: Special Data Type Declaration and Usage Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-11-16 06:42 -0800
          Re: Special Data Type Declaration and Usage Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-11-16 17:16 +0000
            Re: Special Data Type Declaration and Usage Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-11-17 00:04 -0800
    Re: Special Data Type Declaration and Usage Brian Drummond <brian@shapes.demon.co.uk> - 2011-11-15 22:17 +0000
    Re: Special Data Type Declaration and Usage Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-11-15 22:19 +0000
      Re: Special Data Type Declaration and Usage Ian Collins <ian-news@hotmail.com> - 2011-11-16 11:51 +1300
        Re: Special Data Type Declaration and Usage Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-11-16 00:27 +0000
    Re: Special Data Type Declaration and Usage Paavo Helde <myfirstname@osa.pri.ee> - 2011-11-15 16:28 -0600

#11483 — Special Data Type Declaration and Usage

Frommrc2323@cox.net (Mike Copeland)
Date2011-11-15 14:04 -0700
SubjectSpecial Data Type Declaration and Usage
Message-ID<MPG.292c81c3a91936999896cd@news.eternal-september.org>
   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

[toc] | [next] | [standalone]


#11484

FromIan Collins <ian-news@hotmail.com>
Date2011-11-16 10:09 +1300
Message-ID<9ig2o7Fi5oU5@mid.individual.net>
In reply to#11483
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

[toc] | [prev] | [next] | [standalone]


#11486

From"Gennaro Prota" <gennaro.prota+Usenet@gmail.com>
Date2011-11-15 22:16 +0100
Message-ID<op.v40apype4vph3f@gp.homenet.telecomitalia.it>
In reply to#11483
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.

[toc] | [prev] | [next] | [standalone]


#11487

Frommrc2323@cox.net (Mike Copeland)
Date2011-11-15 14:30 -0700
Message-ID<MPG.292c87c562684f599896ce@news.eternal-september.org>
In reply to#11486
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<{{

[toc] | [prev] | [next] | [standalone]


#11488

FromIan Collins <ian-news@hotmail.com>
Date2011-11-16 10:36 +1300
Message-ID<9ig4bcFi5oU7@mid.individual.net>
In reply to#11487
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

[toc] | [prev] | [next] | [standalone]


#11492

Frommrc2323@cox.net (Mike Copeland)
Date2011-11-15 15:02 -0700
Message-ID<MPG.292c8f618831a8ec9896cf@news.eternal-september.org>
In reply to#11488
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.

[toc] | [prev] | [next] | [standalone]


#11499

FromVictor Bazarov <v.bazarov@comcast.invalid>
Date2011-11-15 18:10 -0500
Message-ID<j9urhf$j0f$1@dont-email.me>
In reply to#11492
On 11/15/2011 5:02 PM, Mike Copeland wrote:
> In article<9ig4bcFi5oU7@mid.individual.net>, ian-news@hotmail.com
> says...
>> On 11/16/11 10:30 AM, Mike Copeland wrote:
>>>      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.

Actually, not orthogonal, but often opposed.  If you want to save 
memory, you will often sacrifice speed and vice versa.  Implement a 
simple vector<char> and see if the speed is sufficient.  If not, make 
sure you have the tools to find out where the time is spent in your 
program, *before* you attempt to speed it up.

V
-- 
I do not respond to top-posted replies, please don't ask

[toc] | [prev] | [next] | [standalone]


#11498

From"Gennaro Prota" <gennaro.prota+Usenet@gmail.com>
Date2011-11-15 23:58 +0100
Message-ID<op.v40fftsw4vph3f@gp.homenet.telecomitalia.it>
In reply to#11487
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.

[toc] | [prev] | [next] | [standalone]


#11512

FromNick Keighley <nick_keighley_nospam@hotmail.com>
Date2011-11-16 06:42 -0800
Message-ID<d6cb952e-8691-442f-8e8f-171401d28bc2@o5g2000yqa.googlegroups.com>
In reply to#11487
On Nov 15, 9:30 pm, mrc2...@cox.net (Mike Copeland) wrote:
> In article <op.v40apype4vp...@gp.homenet.telecomitalia.it>,
> gennaro.prota+Use...@gmail.com says...> On Tue, 15 Nov 2011 22:04:25 +0100, Mike Copeland <mrc2...@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"

the common term for a 4-bit quantity is a "nibble"

Is your data sparse? That is, are there many more default values than
other values? If so consider a sparse array. Only store the non-
default values and return default if the lookup fails.

> > > 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

there are bit fields but I've never been keen. I normally use explicit
masks and shifts to extract bit fields. Something like this:-

<code>

typedef unsigned char Byte;
typedef unsigned char Nibble;

class NibbleContainer
{
public:
    NibbleContainer(size_t size, Nibble default_value = 0);

    size_t size() const { return m_size; }

    void set (size_t i, Nibble nib);
    Nibble get (size_t i) const;
private:
    size_t m_size;
    std::vector<Byte> m_vec;
};

inline bool is_odd (size_t n) { return n % 2 == 1; }

NibbleContainer::NibbleContainer(size_t size, Nibble default_value):
    m_size(size), m_vec ((size + 1) / 2)
{
	for (size_t i = 0; i < size; i++)
		set (i, default_value);
}

void NibbleContainer::set (size_t i, Nibble nib)
{
    assert (i < m_size);
    assert (nib < 16);

    size_t vec_index = i / 2;

    if (is_odd (i))
    {
        // stick it in the top nibble
        nib <<= 4;
        m_vec [vec_index] &= 0x0f;
        m_vec [vec_index] |= nib;
    }
    else
    {
        // stick it in the bottom nibble
        m_vec [vec_index] &= 0xf0;
        m_vec [vec_index] |= nib;
    }
}

Nibble NibbleContainer::get (size_t i) const
{
    assert (i < m_size);
    size_t vec_index = i / 2;

    if (is_odd (i))
        // get it from the top nibble
        return (m_vec [vec_index] >> 4) & 0x0f;
    else
        // get it from the bottom nibble
        return m_vec [vec_index] & 0x0f;

}

</code>

now that amount of c-like c++ is bound to provoke a reaction...

> > 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...

depends what "efficient" means. How many non-defaults do you have? How
often do they change? How often do you read a value? How often do you
write a value? etc. etc. You need to measure things and get some hard
numebrs.

[toc] | [prev] | [next] | [standalone]


#11519

FromJorgen Grahn <grahn+nntp@snipabacken.se>
Date2011-11-16 17:16 +0000
Message-ID<slrnjc7run.1bk.grahn+nntp@frailea.sa.invalid>
In reply to#11512
On Wed, 2011-11-16, Nick Keighley wrote:
> On Nov 15, 9:30 pm, mrc2...@cox.net (Mike Copeland) wrote:
>> In article <op.v40apype4vp...@gp.homenet.telecomitalia.it>,
>> gennaro.prota+Use...@gmail.com says...> On Tue, 15 Nov 2011 22:04:25 +0100, Mike Copeland <mrc2...@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"
>
> the common term for a 4-bit quantity is a "nibble"
...

> there are bit fields but I've never been keen. I normally use explicit
> masks and shifts to extract bit fields. Something like this:-
>
> <code>
>
> typedef unsigned char Byte;
> typedef unsigned char Nibble;
>
> class NibbleContainer
> {
> public:
>     NibbleContainer(size_t size, Nibble default_value = 0);
>
>     size_t size() const { return m_size; }
>
>     void set (size_t i, Nibble nib);
>     Nibble get (size_t i) const;
> private:
>     size_t m_size;
>     std::vector<Byte> m_vec;
> };
...
> </code>
>
> now that amount of c-like c++ is bound to provoke a reaction...

If all C-like C++ was /that/ C++-like, I wouldn't dislike it so much!

Seriously, it looked perfectly fine. I'd do it exactly like that
(except I probably would use 'unsigned' instead of that 'Nibble'
typedef).

/Jorgen

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

[toc] | [prev] | [next] | [standalone]


#11553

FromNick Keighley <nick_keighley_nospam@hotmail.com>
Date2011-11-17 00:04 -0800
Message-ID<7ab29629-c6d1-489e-9496-89580505daa3@y7g2000vbe.googlegroups.com>
In reply to#11519
On Nov 16, 5:16 pm, Jorgen Grahn <grahn+n...@snipabacken.se> wrote:
> On Wed, 2011-11-16, Nick Keighley wrote:
> > On Nov 15, 9:30 pm, mrc2...@cox.net (Mike Copeland) wrote:
> >> In article <op.v40apype4vp...@gp.homenet.telecomitalia.it>,
> >> gennaro.prota+Use...@gmail.com says...> On Tue, 15 Nov 2011 22:04:25 +0100, Mike Copeland <mrc2...@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"
>
> > the common term for a 4-bit quantity is a "nibble"
>
> ...
>
> > there are bit fields but I've never been keen. I normally use explicit
> > masks and shifts to extract bit fields. Something like this:-
>
> > <code>
>
> > typedef unsigned char Byte;
> > typedef unsigned char Nibble;
>
> > class NibbleContainer
> > {
> > public:
> >     NibbleContainer(size_t size, Nibble default_value = 0);
>
> >     size_t size() const { return m_size; }
>
> >     void set (size_t i, Nibble nib);
> >     Nibble get (size_t i) const;
> > private:
> >     size_t m_size;
> >     std::vector<Byte> m_vec;
> > };
> ...
> > </code>
>
> > now that amount of c-like c++ is bound to provoke a reaction...
>
> If all C-like C++ was /that/ C++-like, I wouldn't dislike it so much!
>
> Seriously, it looked perfectly fine. I'd do it exactly like that
> (except I probably would use 'unsigned' instead of that 'Nibble'
> typedef).

I was trying to express the semantics that it was intended to hold
only 4 bits rather than 8. But without the cost of full-blown class.

Even if my class doesn't serve his purpose once he's encapsulated it
he can change the representation without it messing up the rest of his
program. It can be a straight vector (as other posters have suggested)
or my packed representation or a sparse array (or hash or tree). etc.
etc.

A good software engineerign lesson is if you have hard decision (or
any decsion!) to make then hide it from the rest of the program. In C+
+ a class is often a good way to do this (not to denigrate templates
etc.).

[toc] | [prev] | [next] | [standalone]


#11494

FromBrian Drummond <brian@shapes.demon.co.uk>
Date2011-11-15 22:17 +0000
Message-ID<j9uoe1$gom$2@dont-email.me>
In reply to#11483
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

[toc] | [prev] | [next] | [standalone]


#11495

FromJorgen Grahn <grahn+nntp@snipabacken.se>
Date2011-11-15 22:19 +0000
Message-ID<slrnjc5pc2.1bk.grahn+nntp@frailea.sa.invalid>
In reply to#11483
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   .

[toc] | [prev] | [next] | [standalone]


#11497

FromIan Collins <ian-news@hotmail.com>
Date2011-11-16 11:51 +1300
Message-ID<9ig8nfFi5oU9@mid.individual.net>
In reply to#11495
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

[toc] | [prev] | [next] | [standalone]


#11500

FromJorgen Grahn <grahn+nntp@snipabacken.se>
Date2011-11-16 00:27 +0000
Message-ID<slrnjc60qm.1bk.grahn+nntp@frailea.sa.invalid>
In reply to#11497
On Tue, 2011-11-15, Ian Collins wrote:
> 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.

Thus "won't easily be able to".  But yes -- it's worth pointing out
that if he really wants array-style syntax he can get it.  (I think
I'd normally settle for a small_things.set(index, value) function.)

/Jorgen

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

[toc] | [prev] | [next] | [standalone]


#11496

FromPaavo Helde <myfirstname@osa.pri.ee>
Date2011-11-15 16:28 -0600
Message-ID<Xns9F9F4E26FDCEmyfirstnameosapriee@216.196.109.131>
In reply to#11483
mrc2323@cox.net (Mike Copeland) wrote in 
news:MPG.292c81c3a91936999896cd@news.eternal-september.org:

>    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.

Unless your program is meant to run on some tiny embedded processor, stop 
worrying about this. 100,000 bytes is most probably less than 0.01% of the 
memory in your computer, spend your time on something more useful instead!

Cheers
Paavo

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web