Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8908709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:15:07+00:00 2026-06-15T03:15:07+00:00

I would like to optimize the reading of an InputStream, then I thought it

  • 0

I would like to optimize the reading of an InputStream, then I thought it would be good to have a byte[] buffer with the size of a RAM page.

Is there a method (possibly a static one) to know its size?

EDIT:

Finally I succeeded using NDK and JNI, I wrote the following code in C:

#include <jni.h>
#include <unistd.h>

jlong Java_it_masmil_tests_TestsActivity_pageSize(JNIEnv* env, jobject javaThis) {
    return sysconf(_SC_PAGE_SIZE);
}

where:

  • it.masmil.tests is the package name
  • TestsActivity is the class name
  • pageSize is the method name
  • env and javaThis are two mandatory parameters (usefull in some occasions)

I compiled that file with NDK, and then I wrote the following code in Java:

static {
    System.loadLibrary("clibrary");
}
private native long pageSize();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    long page = pageSize();
}

where:

  • clibrary is the name of the library I created with NDK
  • pageSize is the name of the method as declared in the C file
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:15:09+00:00Added an answer on June 15, 2026 at 3:15 am

    Page size is defined by Linux (kernel) and you can get it via JNI by calling libc (bionic)’s sysconf(_SC_PAGESIZE). Since Android runs on Linux and mostly on ARM systems, you can assume 4k page sizes.

    #include <unistd.h>
    long sz = sysconf(_SC_PAGESIZE);
    

    However you can’t really get this kind of alignment from Java/C easily. Meaning even if you ask for a 4k block, no one guarantees that will be 4k aligned.

    In case you need a 4k aligned block on Linux, you should use mmap which is guaranteed to be page size aligned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL query that I would like to optimize a little bit.
I have many complex SQL queries that I would like to optimize. The performance
I would like to optimize the following code in R. This loop takes a
I would like to implement an B+ tree in Java and try to optimize
I would like to optimize a part of my program where I'm calculating the
I am working with ASP.NET MVC 2 and would like to optimize my routing.
I would like to use Panda3D for my personal project, but after reading the
I would like to optimize the following code. Currently it runs around 0.085 seconds
I would like to know if there is any possibility to get a Path
I would like to know if there is an equivelent tool like sql profiler

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.