-2

I can't find the relative code to the native methods memchr, memcmp, memcpy, memmove, memset in Java. Could someone explain what do these methods stand for? What do they really do?

I want to acceed to the value pointed to by a variable in my program and I'm wondering if these methods could help me.

Thank you in advance.

riroo
  • 134
  • 3
  • 15
  • Sorry either your question makes no sense or I cannot understand what you're asking. *"I want to acceed to the value pointed to by a variable"* > There's no need for those functions to access a value pointed by a variable. The variable name is for all purposes the alias for the value it is holding. – m0skit0 Jul 08 '13 at 09:49
  • In fact, I don't want to get the content of the variable itself, but rather the value pointed by it. – riroo Jul 08 '13 at 10:36
  • Why do you have a pointer in Java? This looks like a bad design. Java has no pointer concept, and as such, you cannot do what you're asking. What's the underlying problem you're actually facing? – m0skit0 Jul 08 '13 at 10:57
  • I'm working on JavaCV. I want to track objects using the CamShift algorithm. And it has been told in a forum that in the sample code that we can find on the internet, there's an error in a line of code, we must replace the variable by the value pointed to by the variable. I'm new to Java and JavaCV. That's why I may be asking silly questions. Sorry :( – riroo Jul 08 '13 at 12:48

2 Answers2

3

Java native methods are not encouraged to use unless you can not get the things done using available java methods. Also implementations of native methods can be differ from java versions. If you really want to see them you just download the jdk with source code from openJDK and have a look at them. On the other hand you can have your own implementations for these native methods as well. Have a look at here to get more details on how to override these native methods

Sanjaya Liyanage
  • 4,706
  • 9
  • 36
  • 50
  • Could you please tell what they stand for, in case someone wants to use them? Thank you :) – riroo Jul 08 '13 at 10:34
  • @javacv_newbie sorry I don't have openjdk downloaded jdk7 with me.Refer http://stackoverflow.com/questions/12594046/java-native-method-source-code and you can visit and see what they are. Those methods are changing version to version. Thus can not guarantee what they are in a particular version. Have a look at JNI to find the methods you can override – Sanjaya Liyanage Jul 08 '13 at 10:52
  • Ah okey, I get it. Thanks ;) – riroo Jul 08 '13 at 12:46
0

There aren't any. Therefore your question about what they do doesn't make sense. The closest approach in Java is System.arraycopy().

user207421
  • 305,947
  • 44
  • 307
  • 483
  • -1 I also thought this, but on research I found Java Native methods do exist and do provide the described functionality. Although admittedly it seems like a very bad idea for any normal situation. – Elemental Jul 08 '13 at 09:56
  • @EJP : what does System.arraycopy() do exactly? – riroo Jul 08 '13 at 10:33
  • @Elemental can you think of **any** situation where it does not seem like a bad idea? – selig Jul 08 '13 at 10:37
  • @javacv_newbie: The description in the [Java docs](http://bit.ly/xYIX13) is more thorough than anything anyone can provide here. Please, always check the [manual](https://www.google.com/search?q=system.arraycopy+java). – jason Jul 08 '13 at 10:45
  • I'm afraid it's not what I'm lookin for. Thank you anyway :) – riroo Jul 08 '13 at 10:55
  • @Elemental Java native methods for memcpy() and friends such as what? – user207421 Jul 08 '13 at 11:50
  • @javacv_newbie If what is in the Javadoc isn't what you are looking for, you need to revise your expectations, because that's what you're going to get. People here or elsewhere aren't going to waste their time restating what can already be found there, and I see no reason why you should waste your own time even asking for it, rather than reading what is already provided. Just like we did. – user207421 Jul 08 '13 at 11:52