Skip to content

Instantly share code, notes, and snippets.

@necrophonic
Created March 25, 2019 07:51
Show Gist options
  • Save necrophonic/13ff2d83d2b1f1878e1a4123e0207e97 to your computer and use it in GitHub Desktop.
Save necrophonic/13ff2d83d2b1f1878e1a4123e0207e97 to your computer and use it in GitHub Desktop.
A collection of useful functions that don't fit in their own repos or libs but don't want to lose
/*
Useful functions for various random things.
Collected here as they don't justify full repos / libraries of their own
/*
// JAVA Analysis
// StringSizeInBytes determines the size of a java string in bytes given the number of chars in it.
// https://stackoverflow.com/questions/31206851/how-much-memory-does-a-string-use-in-java-8
func StringSizeInBytes(numChars int, isJava8 bool) int {
b := (8 * (int)(((numChars * 2) + 45)/8))
if isJava8 {
// Java 8 does not have the offset and length anymore (8 bytes worth)
return b - 8
}
return b
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment