Giter Site home page Giter Site logo

sharedmemory's Introduction

Shared Memory

The Shared Memory library allows for the creation of memory regions that may be simultaneously accessed by multiple Android processes or applications. Developed to overcome the Android 1MB IPC limitation, this Shared Memory library allows you to exchange larger amounts of data between your Android applications.


How to Use

Setup

Include the below dependencies in your build.gradle project.

buildscript {
    repositories {
        google()
        maven { url "https://newtronlabs.jfrog.io/artifactory/libs-release-local" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.4'
        classpath 'com.newtronlabs.android:plugin:5.0.2'
    }
}

allprojects {
    repositories {
        google()
        maven { url "https://newtronlabs.jfrog.io/artifactory/libs-release-local" }
    }
}

subprojects {
    apply plugin: 'com.newtronlabs.android'
}

In the build.gradle for your app.

dependencies {
    compileOnly 'com.newtronlabs.sharedmemory:sharedmemory:5.0.0-alpha01'
}

Sharing Memory - Producer

From the application that wishes to shared its memory, allocate a shated memory region with a given name.

// Allocate 2MB
int sizeInBytes = 2*(1024*1024);
String regionName = "Test-Region";
ISharedMemory sharedMemory = SharedMemoryProducer.getInstance().allocate(regionName, sizeInBytes);

Write data to memory:

byte[] strBytes = "Hello World!".getBytes();
sharedMemory.writeBytes(strBytes, 0, 0, strBytes.length);

Once an application has shared a memory region it can be accessed by other processes or application which are aware of it.

Accessing Shared Memory - Consumer

In order for an application to access a region of memory shaered by an external application perform the following:

// This is the application id of the application or process which shared the region.
String producerAppId = "com.newtronlabs.smproducerdemo";

// Name under wich the remote region was created.
String regionName = "Test-Region"

// Note: The remote application must have allocated a memory region with the same
//       name or this call will fail and return null.
IRemoteSharedMemory remoteMemory 
         = RemoteMemoryAdapter.getDefaultAdapter().getSharedMemory(context, producerAppId, regionName);

// Allocate memory to read shared content.
byte[] dataBytes = new byte[remoteMemory.getSize()];
String dataStr = new String(dataBytes);
Log.d("Newtron", "Memory Read:"+dataStr);

Additional Samples

A set of more complex exmaples can be found in this repo's samples folders: SmProducer and SmConsumer.


Support Us

Please support the continued development of these libraries. We host and develop these libraries for free. Any support is deeply appriciated. Thank you!

Support us

BTC Address: 39JmAfnNhaEPKz5wjQjQQj4jcv9BM11NQb


License

https://gist.github.com/NewtronLabs/216f45db2339e0bc638e7c14a6af9cc8

Contact

[email protected]

sharedmemory's People

Contributors

newtronlabs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

sharedmemory's Issues

Error:Resolving configuration 'androidTestCompile' directly is not allowed when trying to add to gradle

Hi!

I'm trying to add SharedMemory to Gradle

After syncing files, I get this error:
Error:Resolving configuration 'androidTestCompile' directly is not allowed

My build.gradle project:

buildscript {
    ext.kotlin_version = '1.2.20'

    repositories {
        google()
        jcenter()
        maven { url "http://code.newtronlabs.com:8081/artifactory/libs-release-local" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.newtronlabs.android:plugin:1.1.0"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        flatDir {
            dirs 'libs'
        }
        maven { url "http://code.newtronlabs.com:8081/artifactory/libs-release-local" }
        maven { url "http://dl.bintray.com/steveliles/maven" }
    }
}

subprojects {
    apply plugin: 'com.newtronlabs.android'
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

My build.gradle app:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
    compileSdkVersion 26



    defaultConfig {
        applicationId "com.eyeclick.engineui"
        minSdkVersion 23
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation project(':astra_api')
    compile 'org.opencv:OpenCV-Android:3.1.0'
    implementation project(':eyeengine')
    provided 'com.newtronlabs.sharedmemory:sharedmemory:2.0.0'
}

getDefaultAdapter() throws java.lang.RuntimeException: Stub!

Hi,
The issue is very simple as explained in the title - the RemoteMemoryAdapter.getDefaultAdapter() method does nothing other but throws a RuntimeException. Am I missing something?

Also, in the readme, you forgot to include remoteMemory.readBytes(bytes, 0, 0, bytes.length); in the part about the consumer. Though the examples are very clear about that. What they aren't clear about is what happens to the bytes already present in the memory, if I reuse it and say write a smaller amount of bytes. Does the remainder of the old ones stay there?

POM file is missing, and it's your fault

http://code.newtronlabs.com:8081/artifactory/libs-release-local/com/newtronlabs/android/plugin/4.0.0/

Tried to the add the dependency to android studio project, error thrown saying that POM file not found.
I checked the URL, and I don't see the POM file.

Seriously, are you truly let us developers to use your library or not? Aside from such stringent license and closed-source nature, it's so hard to integrate because you don't even provide the pom file.

Fix it, quick.

My I ask some details

Is this library built on MemoryFile?If so, how does it pass file descriptor between processes?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.