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


Groups > comp.lang.java.programmer > #21529

Re: creating byte[] with subfields

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From Jim Janney <jjanney@shell.xmission.com>
Newsgroups comp.lang.java.programmer
Subject Re: creating byte[] with subfields
Date Fri, 18 Jan 2013 10:29:42 -0700
Organization a light protective coating of dust
Lines 20
Message-ID <ydnehhiqu0p.fsf@shell.xmission.com> (permalink)
References <o62if8p1orppd2poseimactf3rqu0s04kn@4ax.com> <ydnip6uqzie.fsf@shell.xmission.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Info mx04.eternal-september.org; posting-host="75975abe3fe3503ca7350803ab98e478"; logging-data="23530"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19EPSJ4xKiHhc1mKdwzKjsr"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)
Cancel-Lock sha1:52Bm+xWHp7CeGvzQzzJS3rrsSio= sha1:SJlv2X4QYm/OKdLjYQ/T2dPo5ME=
Xref csiph.com comp.lang.java.programmer:21529

Show key headers only | View raw


Jim Janney <jjanney@shell.xmission.com> writes:

> Roedy Green <see_website@mindprod.com.invalid> writes:
>
>> I often have to construct byte arrays with binary fields, or read
>> them.
>>
>> I use a ByteArrayOutputStream and a DataOutputStream to compose them.
>> I wondered if there is a simpler way, one that does not require
>> computing each byte individually with shifts.
>
> In C, sure.  Java by design doesn't allow those kinds of tricks.

The hotspot compiler might notice that you're shifting and masking by 8
bits and replace it with direct byte addressing.  That seems like a
straightforward optimization.  OTOH, the speed difference is probably
too tiny to notice anyway.

-- 
Jim Janney

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

creating byte[] with subfields Roedy Green <see_website@mindprod.com.invalid> - 2013-01-18 00:35 -0800
  Re: creating byte[] with subfields Jim Janney <jjanney@shell.xmission.com> - 2013-01-18 08:31 -0700
    Re: creating byte[] with subfields Jim Janney <jjanney@shell.xmission.com> - 2013-01-18 10:29 -0700
  Re: creating byte[] with subfields Nigel Wade <nmw@ion.le.ac.uk> - 2013-01-18 16:23 +0000
  Re: creating byte[] with subfields Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-01-18 10:53 -0800
    Re: creating byte[] with subfields Roedy Green <see_website@mindprod.com.invalid> - 2013-01-18 14:23 -0800
      Re: creating byte[] with subfields Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-01-18 15:16 -0800
        Re: creating byte[] with subfields Roedy Green <see_website@mindprod.com.invalid> - 2013-01-18 23:24 -0800
          Re: creating byte[] with subfields Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-01-19 21:46 -0800
            Re: creating byte[] with subfields Joshua Cranmer <Pidgeot18@verizon.invalid> - 2013-01-20 11:01 -0600
              Re: creating byte[] with subfields Arne Vajhøj <arne@vajhoej.dk> - 2013-01-20 12:54 -0500
            Re: creating byte[] with subfields Arne Vajhøj <arne@vajhoej.dk> - 2013-01-20 12:51 -0500
        Re: creating byte[] with subfields Arne Vajhøj <arne@vajhoej.dk> - 2013-01-19 13:34 -0500
  Re: creating byte[] with subfields Arne Vajhøj <arne@vajhoej.dk> - 2013-01-18 20:33 -0500
    Re: creating byte[] with subfields Arne Vajhøj <arne@vajhoej.dk> - 2013-01-18 20:48 -0500

csiph-web