Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Equivalent of C#-fixed-keyword for Java

Hello everybody,

what is the equivalent of the fixed-keyword of C# for Java?

In other words, how can I translate this code:

Code
fixed (Char* sPtr = s) { //s=Any String variable

                   return converttoFg(sPtr, s.Length); //Any method
               }

to Java?


Regards and thanks
I don't actually think there is an equivalent in Java.

Having read the C# definition, "the fixed statement sets a pointer to a managed variable and "pins" that variable during the execution of the statement", the thing is Java doesn't actually make use of pointers.

Could you explain a use case for this in Java?
The fixed keyword prevents the garbage collector from relocating the data to another memory adress. So if you have a pointer to something, the GC can move whatever the pointer was pointing to before you need to use it and when you do need it it’s been moved(if not fixed).

Java doesn’t use pointers like C# so afaik there is no equivalent.
Java has no memory management like others have said and fixed in C# is bad practice and unsafe shouldn't be used and I can't see why you would need to
Hello everyone,

thank you for your answers.

I believed that using Pointers you could convert a String to in Char implicitly, as you can see in the example.

But I think that is enough in Java:

Code
return converttoFg(sPtr, s.Length); //Any method


Regards and thank you


Possibly Related Threads...
Thread / Author Replies Views Last Post
by greekdevSep 9, 2026 10:36 AM 2 123 Sep 9, 2026 10:36 AM
Last Post: greekdev
[Python] by simmerOct 27, 2020 04:51 AM 9 305 Oct 27, 2020 04:51 AM
Last Post: simmer
[Java] by Nemo2478Jun 12, 2020 07:41 AM 2 124 Jun 12, 2020 07:41 AM
Last Post: Nemo2478