a string or char

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

Bacardi151

Senior member
Dec 15, 2003
540
0
0
good idea,

but does that mean i have to fill it up with 200K bytes? meaning i have to put it through a 200,000 loop? won't that be very inefficient?
 

element

Diamond Member
Oct 9, 1999
4,635
0
0
Originally posted by: amdfanboy
Originally posted by: element
Originally posted by: Bacardi151
interesting website amdfanboy! thanks!

i'm terribly sorry about posting in this forum, i just need an answer quick and the tech seems to be dead, but i usually get my questions addressed here, so i hope nobody minds.

so here's the deal, i'm trying to make a 200KB size of a variable that i can send from a server to a client (server and client is written in java and i'm just testing the transmission)

anyways, so if i were to use the String myString = "hello" it is actually 6 chars which in turn is 16bits/2bytes each which makes myString 12bytes?

if that's the case, and im trying to make a 200KB variable...out of an array...can i just fill the array's slots 200K/12 times through a loop?

What about the tcp/ip headers, isn't there some overhead with that?

All handled in Java. :p

teh noes! but it still has to send it, along with the data, so It uses up bandwidth, right?
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: element
"When a TCP implementation decides to send a packet of data to the remote peer, it first wraps the data with 20-plus bytes of data called the "header". Headers are an essential part of network protocols, because they enable the participants in the network make decisions regarding the data flowing over it. Every protocol adds headers (and sometimes trailers) to your data."

Java handles this and abstracts it into their stream paradigm.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: element
Originally posted by: amdfanboy
Originally posted by: element
Originally posted by: Bacardi151
interesting website amdfanboy! thanks!

i'm terribly sorry about posting in this forum, i just need an answer quick and the tech seems to be dead, but i usually get my questions addressed here, so i hope nobody minds.

so here's the deal, i'm trying to make a 200KB size of a variable that i can send from a server to a client (server and client is written in java and i'm just testing the transmission)

anyways, so if i were to use the String myString = "hello" it is actually 6 chars which in turn is 16bits/2bytes each which makes myString 12bytes?

if that's the case, and im trying to make a 200KB variable...out of an array...can i just fill the array's slots 200K/12 times through a loop?

What about the tcp/ip headers, isn't there some overhead with that?

All handled in Java. :p

teh noes! but it still has to send it, along with the data, so It uses up bandwidth, right?

And you know some magical way where you wouldn't?
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: Bacardi151
good idea,

but does that mean i have to fill it up with 200K bytes? meaning i have to put it through a 200,000 loop? won't that be very inefficient?

String s = "Hello!";
byte[] strBytes = s.getBytes();
byte[] dataBuffer = new byte[20000];
for(int k = 0; k < strBytes.length; k++)
{
dataBuffer[k] = strBytes[k];
}


*Stupid Fusetalk code
 

element

Diamond Member
Oct 9, 1999
4,635
0
0
Originally posted by: amdfanboy
Originally posted by: element
Originally posted by: amdfanboy
Originally posted by: element
Originally posted by: Bacardi151
interesting website amdfanboy! thanks!

i'm terribly sorry about posting in this forum, i just need an answer quick and the tech seems to be dead, but i usually get my questions addressed here, so i hope nobody minds.

so here's the deal, i'm trying to make a 200KB size of a variable that i can send from a server to a client (server and client is written in java and i'm just testing the transmission)

anyways, so if i were to use the String myString = "hello" it is actually 6 chars which in turn is 16bits/2bytes each which makes myString 12bytes?

if that's the case, and im trying to make a 200KB variable...out of an array...can i just fill the array's slots 200K/12 times through a loop?

What about the tcp/ip headers, isn't there some overhead with that?

All handled in Java. :p

teh noes! but it still has to send it, along with the data, so It uses up bandwidth, right?

And you know some magical way where you wouldn't?


Well there's always UDP which has considerably less header sizes. 4 fields of 2 bytes each so 8 bytes as ooposed to tcp/ip's 20bytes.

w00t pwnage i win gg.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: element
Originally posted by: amdfanboy
Originally posted by: element
Originally posted by: amdfanboy
Originally posted by: element
Originally posted by: Bacardi151
interesting website amdfanboy! thanks!

i'm terribly sorry about posting in this forum, i just need an answer quick and the tech seems to be dead, but i usually get my questions addressed here, so i hope nobody minds.

so here's the deal, i'm trying to make a 200KB size of a variable that i can send from a server to a client (server and client is written in java and i'm just testing the transmission)

anyways, so if i were to use the String myString = "hello" it is actually 6 chars which in turn is 16bits/2bytes each which makes myString 12bytes?

if that's the case, and im trying to make a 200KB variable...out of an array...can i just fill the array's slots 200K/12 times through a loop?

What about the tcp/ip headers, isn't there some overhead with that?

All handled in Java. :p

teh noes! but it still has to send it, along with the data, so It uses up bandwidth, right?

And you know some magical way where you wouldn't?


Well there's always UDP which has considerably less header sizes. 4 fields of 2 bytes each so 8 bytes as ooposed to tcp/ip's 20bytes.

w00t pwnage i win gg.

You can also do that in Java.

See DatagramPacket &amp; DatagramSocket

Simple != bloated
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: Bacardi151
good idea,

but does that mean i have to fill it up with 200K bytes? meaning i have to put it through a 200,000 loop? won't that be very inefficient?

How is allocating 100,000 characters going to be faster than allocation 200,000 bytes? I mean, either one will probably take a modern computer at least 0.1 seconds. We were discussing randomly generating arrays of characters with 3,000,000 million entries in software earlier - and doing it in as little as 0.8 seconds.
 

element

Diamond Member
Oct 9, 1999
4,635
0
0
Originally posted by: amdfanboy
Originally posted by: element
Originally posted by: amdfanboy
Originally posted by: element
Originally posted by: amdfanboy
Originally posted by: element
Originally posted by: Bacardi151
interesting website amdfanboy! thanks!

i'm terribly sorry about posting in this forum, i just need an answer quick and the tech seems to be dead, but i usually get my questions addressed here, so i hope nobody minds.

so here's the deal, i'm trying to make a 200KB size of a variable that i can send from a server to a client (server and client is written in java and i'm just testing the transmission)

anyways, so if i were to use the String myString = "hello" it is actually 6 chars which in turn is 16bits/2bytes each which makes myString 12bytes?

if that's the case, and im trying to make a 200KB variable...out of an array...can i just fill the array's slots 200K/12 times through a loop?

What about the tcp/ip headers, isn't there some overhead with that?

All handled in Java. :p

teh noes! but it still has to send it, along with the data, so It uses up bandwidth, right?

And you know some magical way where you wouldn't?


Well there's always UDP which has considerably less header sizes. 4 fields of 2 bytes each so 8 bytes as ooposed to tcp/ip's 20bytes.

w00t pwnage i win gg.

You can also do that in Java.

See DatagramPacket &amp; DatagramSocket

Simple != bloated

Oh yeah i never said you couldn't do it in java, but java is still bloaty. I remember reading about one of those AI bots like Alice and the java source was 64Megs but the c++ implementation was only 2Megs!
 

Bacardi151

Senior member
Dec 15, 2003
540
0
0
Originally posted by: notfred
Originally posted by: Bacardi151
good idea,

but does that mean i have to fill it up with 200K bytes? meaning i have to put it through a 200,000 loop? won't that be very inefficient?

How is allocating 100,000 characters going to be faster than allocation 200,000 bytes? I mean, either one will probably take a modern computer at least 0.1 seconds. We were discussing randomly generating arrays of characters with 3,000,000 million entries in software earlier - and doing it in as little as 0.8 seconds.

i initially actually made a string of 50 chars, which would in turn be 100bytes, meaning i only have to do a for loop of 2,000 loops.

doing a 200,000 loop will cost 100 times more of efficiency, won't it?

i never used the type bytes, i'm a java newb, can i just assign a number to a byte?

i.e. byte data = 5;

would that make the data variable of size 1byte? and is it initialized appropriately?
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: Bacardi151
Originally posted by: notfred
Originally posted by: Bacardi151
good idea,

but does that mean i have to fill it up with 200K bytes? meaning i have to put it through a 200,000 loop? won't that be very inefficient?

How is allocating 100,000 characters going to be faster than allocation 200,000 bytes? I mean, either one will probably take a modern computer at least 0.1 seconds. We were discussing randomly generating arrays of characters with 3,000,000 million entries in software earlier - and doing it in as little as 0.8 seconds.

i initially actually made a string of 50 chars, which would in turn be 100bytes, meaning i only have to do a for loop of 2,000 loops.

doing a 200,000 loop will cost 100 times more of efficiency, won't it?

i never used the type bytes, i'm a java newb, can i just assign a number to a byte?

i.e. byte data = 5;

would that make the data variable of size 1byte? and is it initialized appropriately?

Can you explain why doing 100 things 2000 times is faster than doing 1 thing 200000 times?

And yes, a byte is an 8 bit number. byte low = -128; byte high = 127;
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: element
Originally posted by: amdfanboy
Originally posted by: element
Originally posted by: amdfanboy
Originally posted by: element
Originally posted by: amdfanboy
Originally posted by: element
Originally posted by: Bacardi151
interesting website amdfanboy! thanks!

i'm terribly sorry about posting in this forum, i just need an answer quick and the tech seems to be dead, but i usually get my questions addressed here, so i hope nobody minds.

so here's the deal, i'm trying to make a 200KB size of a variable that i can send from a server to a client (server and client is written in java and i'm just testing the transmission)

anyways, so if i were to use the String myString = "hello" it is actually 6 chars which in turn is 16bits/2bytes each which makes myString 12bytes?

if that's the case, and im trying to make a 200KB variable...out of an array...can i just fill the array's slots 200K/12 times through a loop?

What about the tcp/ip headers, isn't there some overhead with that?

All handled in Java. :p

teh noes! but it still has to send it, along with the data, so It uses up bandwidth, right?

And you know some magical way where you wouldn't?


Well there's always UDP which has considerably less header sizes. 4 fields of 2 bytes each so 8 bytes as ooposed to tcp/ip's 20bytes.

w00t pwnage i win gg.

You can also do that in Java.

See DatagramPacket &amp; DatagramSocket

Simple != bloated

Oh yeah i never said you couldn't do it in java, but java is still bloaty. I remember reading about one of those AI bots like Alice and the java source was 64Megs but the c++ implementation was only 2Megs!

Somehow I can't see that.
 

Bacardi151

Senior member
Dec 15, 2003
540
0
0
Originally posted by: notfred
Originally posted by: Bacardi151
Originally posted by: notfred
Originally posted by: Bacardi151
good idea,

but does that mean i have to fill it up with 200K bytes? meaning i have to put it through a 200,000 loop? won't that be very inefficient?

How is allocating 100,000 characters going to be faster than allocation 200,000 bytes? I mean, either one will probably take a modern computer at least 0.1 seconds. We were discussing randomly generating arrays of characters with 3,000,000 million entries in software earlier - and doing it in as little as 0.8 seconds.

i initially actually made a string of 50 chars, which would in turn be 100bytes, meaning i only have to do a for loop of 2,000 loops.

doing a 200,000 loop will cost 100 times more of efficiency, won't it?

i never used the type bytes, i'm a java newb, can i just assign a number to a byte?

i.e. byte data = 5;

would that make the data variable of size 1byte? and is it initialized appropriately?

Can you explain why doing 100 things 2000 times is faster than doing 1 thing 200000 times?

And yes, a byte is an 8 bit number. byte low = -128; byte high = 127;

i'm doing one thing 2000 times, whereas the other is doing one thing 200K times, right?

because i'm initializing the myString to a message with 50 chars (including the null char).

in either case, i decided to make a looooong string of 100,000 chars, as i'm using a PrintWriter to send out the message to the client, and i dunno on how to go on about using PrintWriter to send an array.

thanks for all the responses though, it has surely informed me of certain things

 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: Bacardi151
i'm doing one thing 2000 times, whereas the other is doing one thing 200K times, right?

because i'm initializing the myString to a message with 50 chars (including the null char).

in either case, i decided to make a looooong string of 100,000 chars, as i'm using a PrintWriter to send out the message to the client, and i dunno on how to go on about using PrintWriter to send an array.

thanks for all the responses though, it has surely informed me of certain things

You should learn how this works at a lower level. When the computer actually runs your code, it reads an instruction with a value attached to it, then assigns it to a particular byte of physical memory. It then repeats this step 100 times for each byte in your array of 50 chars. At that point, it's assigned 100 bytes of memory, one at a time. It then starts over and assigns 100 more bytes of memory, and repeats the process 2000 times.

In my code, the exact same thing happens, except it only assigns a single byte before it jumps back up to the top and starts over. Either way, the same number of bytes are assigned, one at a time.
 

element

Diamond Member
Oct 9, 1999
4,635
0
0
Originally posted by: amdfanboy
Originally posted by: element

Oh yeah i never said you couldn't do it in java, but java is still bloaty. I remember reading about one of those AI bots like Alice and the java source was 64Megs but the c++ implementation was only 2Megs!

Somehow I can't see that.

Ask ALICE yourself:
[/i]http://alice.pandorabots.com/
i did:
Human: how big is your java code?
ALICE: My memory requirement is around 64MB for the Java edition, or only 2 MB for the C/C++ edition.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: element
Originally posted by: amdfanboy
Originally posted by: element

Oh yeah i never said you couldn't do it in java, but java is still bloaty. I remember reading about one of those AI bots like Alice and the java source was 64Megs but the c++ implementation was only 2Megs!

Somehow I can't see that.

Ask ALICE yourself:
[/i]http://alice.pandorabots.com/
i did:
Human: how big is your java code?
ALICE: My memory requirement is around 64MB for the Java edition, or only 2 MB for the C/C++ edition.


Ohh, you said the source was 64Mb. You mean RAM. Yeah, the JVM takes a good amount, but it rarely uses anywhere near that much.

 

element

Diamond Member
Oct 9, 1999
4,635
0
0
Originally posted by: amdfanboy
Originally posted by: element
Originally posted by: amdfanboy
Originally posted by: element

Oh yeah i never said you couldn't do it in java, but java is still bloaty. I remember reading about one of those AI bots like Alice and the java source was 64Megs but the c++ implementation was only 2Megs!

Somehow I can't see that.

Ask ALICE yourself:
[/i]http://alice.pandorabots.com/
i did:
Human: how big is your java code?
ALICE: My memory requirement is around 64MB for the Java edition, or only 2 MB for the C/C++ edition.


Ohh, you said the source was 64Mb. You mean RAM. Yeah, the JVM takes a good amount, but it rarely uses anywhere near that much.

yeah my memory failed me there its been a while since i last read it. But it's even worse that it's the memory requirement than the source code size since what's in memory while its running is what determines bloatness, or how big it is while running hence the slowness in speed of execution.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: element
Originally posted by: amdfanboy
Originally posted by: element
Originally posted by: amdfanboy
Originally posted by: element

Oh yeah i never said you couldn't do it in java, but java is still bloaty. I remember reading about one of those AI bots like Alice and the java source was 64Megs but the c++ implementation was only 2Megs!

Somehow I can't see that.

Ask ALICE yourself:
[/i]http://alice.pandorabots.com/
i did:
Human: how big is your java code?
ALICE: My memory requirement is around 64MB for the Java edition, or only 2 MB for the C/C++ edition.


Ohh, you said the source was 64Mb. You mean RAM. Yeah, the JVM takes a good amount, but it rarely uses anywhere near that much.

yeah my memory failed me there its been a while since i last read it. But it's even worse that it's the memory requirement than the source code size since what's in memory while its running is what determines bloatness, or how big it is while running hence the slowness in speed of execution.

Not really. For most things the user or IO is your slowest factor. OTOH, I wouldn't use it if I wanted high performance.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: element
"It's not a lie, more of a twist of the truth." - lordtyranus

from your sig ;)

Well, Java has it's purpose. It's obviously not designed for HPC. It was designed for portability.
 

element

Diamond Member
Oct 9, 1999
4,635
0
0
Originally posted by: amdfanboy
Originally posted by: element
"It's not a lie, more of a twist of the truth." - lordtyranus

from your sig ;)

Well, Java has it's purpose. It's obviously not designed for HPC. It was designed for portability.

agreed.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Originally posted by: element
Well there's always UDP which has considerably less header sizes. 4 fields of 2 bytes each so 8 bytes as ooposed to tcp/ip's 20bytes.

You really think TCP/IP overhead is going to be a performance problem? You don't need your data to be intact when it reaches the other end?

w00t pwnage i win gg.

:roll:

Seems pretty obvious to me that you haven't been "winning" much in this thread.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: BingBongWongFooey
Originally posted by: element
Well there's always UDP which has considerably less header sizes. 4 fields of 2 bytes each so 8 bytes as ooposed to tcp/ip's 20bytes.

You really think TCP/IP overhead is going to be a performance problem? You don't need your data to be intact when it reaches the other end?

w00t pwnage i win gg.

:roll:

Seems pretty obvious to me that you haven't been "winning" much in this thread.

He's from P&amp;N. He always wins IHO.