dmendel / bindata

BinData - Reading and Writing Binary Data in Ruby
BSD 2-Clause "Simplified" License
577 stars 55 forks source link

[Question] How do I deel with a packet with large payload? #66

Closed kota65535 closed 8 years ago

kota65535 commented 8 years ago

It may be not appropriate to ask the question like this here...

I'm working with streaming packets that contains jpeg images. Each packets are composed of header, whose size is 136Bytes, and payload, whose size is about 60KB(jpeg image). At first I defined Record class that represents the whose that packets, but when I run my program It takes over 10 seconds to instantiate one record.

Should I redefine Record class which is composed of only the header part of the packets?

dmendel commented 8 years ago

Each packets are composed of header, whose size is 136Bytes, and payload, whose size is about 60KB(jpeg image). At first I defined Record class that represents the whose that packets, but when I run my program It takes over 10 seconds to instantiate one record.

Let me guess, you're defining the payload as an array of :uint8? This will cause many thousands of objects to be created which is why it is slow to instantiate.

If you define the payload as a single :string it should be much faster.

kota65535 commented 8 years ago

Exactly! Now I defined my Record class with payload as :string, and Everything goes well. Thank you very much!