473,799 Members | 3,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting serilized data size

Using the below code I am send multiple sterilized object across an IP port.
This works fine if only one object is received at a time but with packing
sometimes there is more then one object or half an object in the received
data. If I place the data in a memory stream on the received side is there
a way to determine where one ends and the next one start?

Since the deserializer stream seems to move the pointer I am trying to look
at the next couple bytes to determine if there is more data in the stream.
It seems that serialized data starts with 0,1 but I can not confirm this.
Is there maybe a rule?

I have also noticed that the number of bytes recieved is always bigger then
the number of bytes deserizlized, any clue why?

CODE 1
IFormatter f = new BinaryFormatter ();
MemoryStream ms = new MemoryStream();
f.Serialize(ms, cmd);
byte[] b = ms.GetBuffer();
this.socket.Beg inSend(b, 0, b.Length, SocketFlags.Non e, new
AsyncCallback(S end_Callback), this.socket);

CODE 2
IFormatter i = new BinaryFormatter ();
MemoryStream ms = new MemoryStream(o, 0, len);
ms.Position = 0;
while(ms.Positi on < len)
{
long position = ms.Position;
if(!(ms.ReadByt e() == 0 && ms.ReadByte() == 1))
break;
ms.Position = position;

object obj = i.Deserialize(m s);
.....

Regards,
John
Nov 16 '05
14 2277
Sahil Malik wrote:

[ Sahil Malik trying to get large-object-heap problems ]
What am I missing? :)


You are just writing to one MemoryStream, which does have O(n)
mem-usage, it's not an amortization problem (like the one in

Below is the test-program that i originally used to check my assumption.
BTW: That was before .net-sp1, so things may have changed.

I have tried running it again today on SP1, and it doesn't seem to be as
bad anymore. The specific problems I had involved a server that had the
SoapFormatter leak as well, so it may have manifested worse on that machine.

The .NET GC fan-crowd is gonna come down on me like a ton of bricks
saying that the memory-profile of this is just a feature of the GC, not
collecting that memory, reusing it and giving it back to the OS if
needed. But my observation at the time was, that .NET processes using
the large-memory-heap could grind the machine to a halt, and even cause
out-of-memory situations by not releasing memory not referenced by any
object.

The program should use roughly 3*bts.Length[1] memory ~ 30Mb (bts,
stream, bts2) but did eat up all available RAM on an 256Mb machine,
making all other programs swap out, and the machine was unable to
recover from that state, since the TaskManager couldn't start so i was
unable to kill the program.

1. It is checked that the serialization is roughly the size of bts.Length.

--
Helge
Nov 16 '05 #11
Helge Jensen wrote:
mem-usage, it's not an amortization problem (like the one in


ListView, where inserting elements seems to be O(n^2)

--
Helge
Nov 16 '05 #12
Helge Jensen

Yes I am serializing them through the same connection and if I implement
handshaking which I have done in the past with a header showing the expected
size it works fine. Normally protocol stuff: send header with size, read
data until size reached, ack data, send next header/data, etc...

I do try avoid using a memory stream when possible if for no other reason it
has more overhead then a byte array but as far as I am aware the only way to
deserialize the data is to create a memory stream. I try to compensate for
the memory issued but setting values to null when done and also manually
disposing of object when possible. Lets face it .NET like to eat memory and
is not always very quick about giving it back.

As I said I have another application that does handshaking with large data
chucks which I compress before sending and have not really noticed a large
problem with memory usage. I have allocated up to 50 meg chuck, compressed
them down to couple megs and send them, normally the program does not go
over 150 meg usage and that is with debugging turned on.

But yes I agree I am going to have to use some kind of protocol and I will
not put it in a memory stream to decode later. I was just hoping when I
started this thread they MS had built something in that I was not seeing and
based on this thread it does not exist.

Regards,
John
Nov 16 '05 #13
Helge Jensen

Wow, thanks for the code... it will take a while to digest but what I have
seen looks good :)

I put the link and e-mail address in the project so if I find anything I
will update you.

Regards,
John
Nov 16 '05 #14
Sahil Malik

Yes I agree it needs a wrapper.

Regards,
John
Nov 16 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1808
by: Willoughby Bridge | last post by:
Hi - Having trouble getting a multipart series of forms to move to the next form. The problem line is: <form method="post" enctype="multipart/form-data" action="Data_Form1.php"> If the "action" parameter is set to the current form (Data_Form1.php) then the data posts to the table correctly, but it does not move to the next form If the "action" parameter is set to the next form in the series then by clicking "submit" it moves to the...
11
2026
by: KarimL | last post by:
Thanks for your advices... but i need to get the Image height because i dynamically resize the height of my webcontrol based on the image height. More i just have the url (relative parth) to the the image but in design time mode all variables concerning Server or Context ar not set ! ...so I can't use MapPath function to obtain the physical parth of the picture ... So my second question is how to retrieve the physical root path of the...
2
1864
by: lanmou | last post by:
hi, i am creating a form in my application which dynamically creates controls by getting information from a table in ms access database .now i would like it to get the text by using another table . my code: Private Sub frmDataEntry_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & Application.StartupPath & "\customer.mdb") ...
6
2158
by: DBC User | last post by:
I have couple of object I serialise and store them in file between session. If you open the files you could see the string values. I want a way to encrypt the data so that if anyone opens the file they shouldn't be able to read it. Just to increase the security of the system. How can I do this? Thanks.
2
2060
by: jodleren | last post by:
Hi! I am making an option, which opens a small window with a picture in it and data about it. I just want a JS script, which will get the picture size, and then set the window accordingly? BR Sonnich
1
3029
davydany
by: davydany | last post by:
Hey guys...a n00b Here for this site. I'm making a sequence class for my C++ class. And The thing is in the array that I have, lets say i put in {13,17,38,18}, when i see the current values for the array data from 0 to3, I get this {13, JUNK VALUE, 17,38, 18} and JUNK VALUE is like 1.8e831 or something like that. This happens when I use the attach() function and use the current() function to display the values at data I really want to...
2
3584
by: rustyc | last post by:
Well, here's my first post in this forum (other than saying 'HI' over in the hi forum ;-) As I said over there: ... for a little side project at home, I'm writing a ham radio web site in uby/Rails. I started it in Perl and gave up on Perl as I went from the 'display the database information on the web page' to the 're-display the information from the database and allow the user to update the database using the web page' stage and realized...
4
6415
by: rakesh.usenet | last post by:
For a particular application of mine - I need a simulation of byte array output stream. * write data onto a stream * getback the contiguous content as an array later for network transport. My code looks as follows. #include <iostream>
7
4447
vikas251074
by: vikas251074 | last post by:
I am getting error above in following code since few days giving tension day and night. How can I solve this? I am facing since Oct.25. in line no. 362 After doing a lot of homework, I am surrendered to you. <%@ Language=VBScript%> <%Option Explicit%>
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10490
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10260
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10243
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9078
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.