Valhalla Legends Forums Archive | Battle.net Bot Development | Java: CopyMemory equivalent

AuthorMessageTime
Tuberload
Is there an equivalent library in java to the CopyMemory API?
April 17, 2003, 5:01 PM
tA-Kane
[quote author=Tuberload link=board=17;threadid=1078;start=0#msg8001 date=1050598863]
Is there an equivalent library in java to the CopyMemory API?
[/quote]Its not hard to make your own, if you cannot find one.

Here's a simple CopyMemory in C:[code]void CopyMemory(char *src, char *dest, int length){
int i;
for (i=0;i++;i<length)
*dest[i] = *src[i];
}[/code]

Of course, if you want to copy an object instead of a string, you'd either have to typecast the object pointers to char pointers when you call this CopyMemory, or create (function overloading is nice...) an alternate CopyMemory designed for use with the object you wish to copy.
April 17, 2003, 7:30 PM
TyC-Pros
This should come in handy for me as well, in Java it would become something like this:

public void CopyMemory(char[] src, char[] dest, int length)
{
int i;
for(i = 0; i < length; i++)
{
dest[i] = src[i];
}
}
April 17, 2003, 11:35 PM
St0rm.iD
[quote author=tA-Kane link=board=17;threadid=1078;start=0#msg8006 date=1050607849]
[quote author=Tuberload link=board=17;threadid=1078;start=0#msg8001 date=1050598863]
Is there an equivalent library in java to the CopyMemory API?
[/quote]Its not hard to make your own, if you cannot find one.

Here's a simple CopyMemory in C:[code]void CopyMemory(char *src, char *dest, int length){
int i;
for (i=0;i++;i<length)
*dest[i] = *src[i];
}[/code]

Of course, if you want to copy an object instead of a string, you'd either have to typecast the object pointers to char pointers when you call this CopyMemory, or create (function overloading is nice...) an alternate CopyMemory designed for use with the object you wish to copy.
[/quote]

Too bad Java doesn't have pointers.

Tuberload: get the 1.4 SDK and take a look at java.nio.ByteBuffer. It should have everything you need except for string ops, which are pretty easy to code yourself. Remember: bytebuffer.order(ByteOrder.LITTLE_ENDIAN), or you'll find yourself IP banned. BTW, they work natively with SocketChannels, which are also nonblocking.

Hope this helps.
April 18, 2003, 1:50 AM
Etheran
[quote author=tA-Kane link=board=17;threadid=1078;start=0#msg8006 date=1050607849]
[quote author=Tuberload link=board=17;threadid=1078;start=0#msg8001 date=1050598863]
Is there an equivalent library in java to the CopyMemory API?
[/quote]Its not hard to make your own, if you cannot find one.

Here's a simple CopyMemory in C:[code]void CopyMemory(char *src, char *dest, int length){
int i;
for (i=0;i++;i<length)
*dest[i] = *src[i];
}[/code]

Of course, if you want to copy an object instead of a string, you'd either have to typecast the object pointers to char pointers when you call this CopyMemory, or create (function overloading is nice...) an alternate CopyMemory designed for use with the object you wish to copy.
[/quote]

You should use void pointers instead :p
April 19, 2003, 12:03 AM
tA-Kane
[quote author=Etheran link=board=17;threadid=1078;start=0#msg8077 date=1050710582]You should use void pointers instead :p[/quote]I thought about that, but since I don't know how to access/set a void pointer without typecasting, I would just typecast back to a char and do it like it already is.

Being that that could confuse him, I figured I shouldn't do such.
April 19, 2003, 1:30 AM
Skywing
[quote author=tA-Kane link=board=17;threadid=1078;start=0#msg8079 date=1050715851]
[quote author=Etheran link=board=17;threadid=1078;start=0#msg8077 date=1050710582]You should use void pointers instead :p[/quote]I thought about that, but since I don't know how to access/set a void pointer without typecasting, I would just typecast back to a char and do it like it already is.

Being that that could confuse him, I figured I shouldn't do such.
[/quote]
You can't. What one would do is put have the prototype take void* parameters, and inside the function body, create seperate identifiers which are cast to char*. That way, your callers don't need to cast every time.
April 19, 2003, 1:35 AM
Eibro
[quote author=tA-Kane link=board=17;threadid=1078;start=0#msg8006 date=1050607849]
[quote author=Tuberload link=board=17;threadid=1078;start=0#msg8001 date=1050598863]
Is there an equivalent library in java to the CopyMemory API?
[/quote]Its not hard to make your own, if you cannot find one.

Here's a simple CopyMemory in C:[code]void CopyMemory(char *src, char *dest, int length){
int i;
for (i=0;i++;i<length)
*dest[i] = *src[i];
}[/code]
[/quote]Eh, that wouldn't work. Either use dest[i] = src[i] or *dest = *src. Using both together you're actually derefrencing the pointers twice.
April 20, 2003, 5:31 PM
iago
[quote author=St0rm.iD link=board=17;threadid=1078;start=0#msg8011 date=1050630636]
[quote author=tA-Kane link=board=17;threadid=1078;start=0#msg8006 date=1050607849]
[quote author=Tuberload link=board=17;threadid=1078;start=0#msg8001 date=1050598863]
Is there an equivalent library in java to the CopyMemory API?
[/quote]Its not hard to make your own, if you cannot find one.

Here's a simple CopyMemory in C:[code]void CopyMemory(char *src, char *dest, int length){
int i;
for (i=0;i++;i<length)
*dest[i] = *src[i];
}[/code]

Of course, if you want to copy an object instead of a string, you'd either have to typecast the object pointers to char pointers when you call this CopyMemory, or create (function overloading is nice...) an alternate CopyMemory designed for use with the object you wish to copy.
[/quote]

Too bad Java doesn't have pointers.

Tuberload: get the 1.4 SDK and take a look at java.nio.ByteBuffer. It should have everything you need except for string ops, which are pretty easy to code yourself. Remember: bytebuffer.order(ByteOrder.LITTLE_ENDIAN), or you'll find yourself IP banned. BTW, they work natively with SocketChannels, which are also nonblocking.

Hope this helps.
[/quote]


That's a lie, Java has pointers, they're everywhere. They're just hidden under a cute little layer saying "Look that's not a pointer! That's a reference! Look over there [runs]"


Anyway, Eibro's right, you are dereferencing the pointer twice in that c++ code and it won't work.
April 20, 2003, 5:53 PM
St0rm.iD
A reference is an auto-dereferenced pointer. All objects in Java are pointers that you cannot get the address of. Thus, all objects in Java are references.

$t0rm: 2
Iago: 0
April 20, 2003, 8:54 PM
Camel
[quote author=St0rm.iD link=board=17;threadid=1078;start=0#msg8128 date=1050872091]
A reference is an auto-dereferenced pointer. All objects in Java are pointers that you cannot get the address of. Thus, all objects in Java are references.

$t0rm: 2
Iago: 0
[/quote]

sort of like vb, except you can do varptr/objptr/strptr/byval -_-
April 21, 2003, 2:18 PM
St0rm.iD
BTW, if you need "real" copy memory, look into System.arraycopy() and java.lang.Cloneable.
April 21, 2003, 4:12 PM
tA-Kane
Obviuously I've still got a lot to learn regarding C/C++. But, I think I've got the basic concept down.
April 21, 2003, 8:29 PM
St0rm.iD
Well, you wouldn't actually NEED CopyMemory in C, because you have memcpy. I suppose it would go like this:
[code]
void copymemory(void* src, void* dest, int len) {
for (int i = 0; i < len; i++) {
*dest = *src;
src++;
dest++;
}
[/code]
April 21, 2003, 11:20 PM
Camel
[quote author=St0rm.iD link=board=17;threadid=1078;start=0#msg8182 date=1050967208]
I suppose it would go like this:
[code]
void copymemory(void* src, void* dest, int len) {
for (int i = 0; i < len; i++) {
*dest = *src;
src++;
dest++;
}
[/code]
[/quote]

or like this:
[code]#define copymemory memcpy[/code]
April 22, 2003, 5:45 AM
Tuberload
Storm: Thank you for the useful info. It was hard to find buried under all the other crap:)

I've been programming in Java about 8 months now and have my Oracle certification and working on getting the sun cert, but there is still a lot to learn.
April 22, 2003, 3:59 PM
Skywing
[quote author=Camel link=board=17;threadid=1078;start=0#msg8199 date=1050990350]
[quote author=St0rm.iD link=board=17;threadid=1078;start=0#msg8182 date=1050967208]
I suppose it would go like this:
[code]
void copymemory(void* src, void* dest, int len) {
for (int i = 0; i < len; i++) {
*dest = *src;
src++;
dest++;
}
[/code]
[/quote]

or like this:
[code]#define copymemory memcpy[/code]
[/quote]That could cause annoying syntax errors; memcpy returns a value, while copymemory does not.
April 22, 2003, 4:52 PM
Camel
since when was it mandatory to recieve what a function returns?
April 22, 2003, 5:03 PM
Skywing
[quote author=Camel link=board=17;threadid=1078;start=15#msg8217 date=1051031030]
since when was it mandatory to recieve what a function returns?
[/quote]It's a good idea when you're replacing a standardized function. Besides, some C compilers have been known to warn about unchecked return values - perhaps you should use (void)memcpy.
April 22, 2003, 5:06 PM
Grok
Skywing you're fighting an uphill battle. Most people are too lazy to be concerned with the proper way to do things. Even though learning these techniques will save them and other people much aggravation in the future, the lazy ones only care that their code compiles right now. Nevermind all the problems that come with being a crappy programmer and distributing crappy code. If it compiles and runs today, it's all they need or care about, right?
April 22, 2003, 5:15 PM
tA-Kane
[quote author=Grok link=board=17;threadid=1078;start=15#msg8221 date=1051031721]Nevermind all the problems[/quote]

As the saying goes, "I'll cross that bridge when I get there."
April 22, 2003, 10:56 PM
St0rm.iD
Or we could just use memcpy and be happy.
April 23, 2003, 12:29 AM
Camel
good call, storm
+1
April 23, 2003, 2:18 AM
St0rm.iD
DAMN, MORE KARMA :(
April 23, 2003, 11:16 PM

Search