From 3e0c5d846636201a7a32400143459ea8d726c40e Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 8 Nov 2012 19:33:32 +0100 Subject: [PATCH] Memory limitation --- .../net/osmand/router/RouteSegmentResult.java | 2 +- .../src/net/osmand/router/routing.xml | 2 +- OsmAnd/jni/Application.mk | 7 +- .../osmand/src/binaryRoutePlanner.cpp | 6 -- Osmand-kernel/osmand/src/binaryRoutePlanner.h | 10 +-- Osmand-kernel/osmand/src/common.h | 8 ++- Osmand-kernel/osmand/src/java_wrap.cpp | 2 - Osmand-kernel/osmand/src/shared_ptr.h | 68 ++++++++----------- 8 files changed, 46 insertions(+), 59 deletions(-) diff --git a/DataExtractionOSM/src/net/osmand/router/RouteSegmentResult.java b/DataExtractionOSM/src/net/osmand/router/RouteSegmentResult.java index 9f035b7b0b..893f930eb8 100644 --- a/DataExtractionOSM/src/net/osmand/router/RouteSegmentResult.java +++ b/DataExtractionOSM/src/net/osmand/router/RouteSegmentResult.java @@ -53,7 +53,7 @@ public class RouteSegmentResult { public RouteSegmentResult[] getPreAttachedRoutes(int routeInd) { int st = Math.abs(routeInd - startPointIndex); - if(st < preAttachedRoutes.length) { + if(preAttachedRoutes != null && st < preAttachedRoutes.length) { return preAttachedRoutes[st]; } return null; diff --git a/DataExtractionOSM/src/net/osmand/router/routing.xml b/DataExtractionOSM/src/net/osmand/router/routing.xml index 1c97fd54f5..0af61e1844 100644 --- a/DataExtractionOSM/src/net/osmand/router/routing.xml +++ b/DataExtractionOSM/src/net/osmand/router/routing.xml @@ -11,7 +11,7 @@ - + diff --git a/OsmAnd/jni/Application.mk b/OsmAnd/jni/Application.mk index 571ed52b96..93ab775280 100755 --- a/OsmAnd/jni/Application.mk +++ b/OsmAnd/jni/Application.mk @@ -7,7 +7,7 @@ APP_ABI := x86 else ifdef OSMAND_ARM_ONLY APP_ABI := armeabi armeabi-v7a -endif +else ifdef OSMAND_ARMv5_ONLY APP_ABI := armeabi endif @@ -16,8 +16,9 @@ APP_ABI := armeabi-v7a endif endif +endif + ifndef OSMAND_DEBUG_NATIVE # Force release compilation in release optimizations, even if application is debuggable by manifest -#APP_OPTIM := release -APP_OPTIM := debug +APP_OPTIM := release endif \ No newline at end of file diff --git a/Osmand-kernel/osmand/src/binaryRoutePlanner.cpp b/Osmand-kernel/osmand/src/binaryRoutePlanner.cpp index 2463791ebe..ff4522f038 100644 --- a/Osmand-kernel/osmand/src/binaryRoutePlanner.cpp +++ b/Osmand-kernel/osmand/src/binaryRoutePlanner.cpp @@ -317,12 +317,6 @@ bool processRouteSegment(RoutingContext* ctx, bool reverseWaySearch, obstacleMinusTime += obstacle; } // could be expensive calculation - // FIXME memory check -// int overhead = (ctx.visitedSegments - ctx.relaxedSegments ) * -// STANDARD_ROAD_IN_QUEUE_OVERHEAD; -// if(overhead > ctx.config.memoryLimitation * 0.95) { -// throw new OutOfMemoryError("There is no enough memory " + ctx.config.memoryLimitation/(1<<20) + " Mb"); -// } SHARED_PTR next = ctx->loadRouteSegment(x, y); // 3. get intersected ways if (next.get() != NULL) { diff --git a/Osmand-kernel/osmand/src/binaryRoutePlanner.h b/Osmand-kernel/osmand/src/binaryRoutePlanner.h index 7dfb413813..7b25c397a1 100644 --- a/Osmand-kernel/osmand/src/binaryRoutePlanner.h +++ b/Osmand-kernel/osmand/src/binaryRoutePlanner.h @@ -189,7 +189,7 @@ struct RoutingConfiguration { distanceRecalculate = parseFloat("recalculateDistanceHelp", 10000) ; } - RoutingConfiguration(vector& config, float initDirection = -360, int memLimit = 100) : + RoutingConfiguration(vector& config, float initDirection = -360, int memLimit = 48) : memoryLimitation(memLimit), initialDirection(initDirection) { for(int j = 0; j > subregions = indexedSubregions[tileId]; + vector >& subregions = indexedSubregions[tileId]; bool gc = false; for(int j = 0; jisLoaded()) { @@ -514,7 +514,7 @@ struct RoutingContext { uint32_t yloc = (y31+j*coordinatesShift) >> (31 - z); int64_t tileId = (xloc << z) + yloc; loadHeaders(xloc, yloc); - vector > subregions = indexedSubregions[tileId]; + vector >& subregions = indexedSubregions[tileId]; for(int j = 0; jisLoaded()) { UNORDERED(map) >::iterator s = subregions[j]->routes.begin(); @@ -545,7 +545,7 @@ struct RoutingContext { uint64_t l = (((uint64_t) x31) << 31) + (uint64_t) y31; int64_t tileId = (xloc << z) + yloc; loadHeaders(xloc, yloc); - vector > subregions = indexedSubregions[tileId]; + vector >& subregions = indexedSubregions[tileId]; for(int j = 0; jisLoaded()) { UNORDERED(map) >::iterator s = subregions[j]->routes.begin(); @@ -575,7 +575,7 @@ struct RoutingContext { uint64_t l = (((uint64_t) x31) << 31) + (uint64_t) y31; int64_t tileId = (xloc << z) + yloc; loadHeaders(xloc, yloc); - vector > subregions = indexedSubregions[tileId]; + vector >& subregions = indexedSubregions[tileId]; UNORDERED(map) > excludeDuplications; SHARED_PTR original; for(int j = 0; j +//# define SHARED_PTR std::tr1::shared_ptr #elif defined(WINDOWS) #else +//# include "shared_ptr.h" +//# define SHARED_PTR my_shared_ptr # include # define SHARED_PTR std::tr1::shared_ptr #endif diff --git a/Osmand-kernel/osmand/src/java_wrap.cpp b/Osmand-kernel/osmand/src/java_wrap.cpp index a2ccca530b..a0ad3f8130 100644 --- a/Osmand-kernel/osmand/src/java_wrap.cpp +++ b/Osmand-kernel/osmand/src/java_wrap.cpp @@ -629,7 +629,6 @@ extern "C" JNIEXPORT jobjectArray JNICALL Java_net_osmand_NativeLibrary_nativeRo jobject obj, jintArray coordinates, jintArray stateConfig, jobjectArray keyConfig, jobjectArray valueConfig, jfloat initDirection, jobjectArray regions) { - vector cfg; int* data = ienv->GetIntArrayElements(stateConfig, NULL); for(int k = 0; k < ienv->GetArrayLength(stateConfig); k++) { @@ -653,7 +652,6 @@ extern "C" JNIEXPORT jobjectArray JNICALL Java_net_osmand_NativeLibrary_nativeRo c.endX = data[2]; c.endY = data[3]; ienv->ReleaseIntArrayElements(coordinates, data, 0); - vector r = searchRouteInternal(&c, false); UNORDERED(map) indexes; for (int t = 0; t< ienv->GetArrayLength(regions); t++) { diff --git a/Osmand-kernel/osmand/src/shared_ptr.h b/Osmand-kernel/osmand/src/shared_ptr.h index b387cab6a2..9e4df7ec90 100644 --- a/Osmand-kernel/osmand/src/shared_ptr.h +++ b/Osmand-kernel/osmand/src/shared_ptr.h @@ -1,49 +1,39 @@ -// Simple shared_ptr implementation based on http://stackoverflow.com/questions/1512520/decent-shared-ptr-implementation-that-does-not-require-a-massive-library -template -class my_shared_ptr { +// http://stackoverflow.com/questions/7792011/alternative-to-boostshared-ptr-in-an-embedded-environment +template +class my_shared_ptr +{ + template + friend class my_shared_ptr; public: - my_shared_ptr() : ptr_(NULL), ref_count_(NULL) { } + my_shared_ptr() :p(), c() {} + explicit my_shared_ptr(T* s) :p(s), c(new unsigned(1)) {} - my_shared_ptr(contained * p) - : ptr_(p), ref_count_(p ? new int : NULL) - { inc_ref(); } + my_shared_ptr(const my_shared_ptr& s) :p(s.p), c(s.c) { if(c) ++*c; } - my_shared_ptr(const my_shared_ptr& rhs) - : ptr_(rhs.ptr_), ref_count_(rhs.ref_count_) - { inc_ref(); } + my_shared_ptr& operator=(const my_shared_ptr& s) + { if(this!=&s) { clear(); p=s.p; c=s.c; if(c) ++*c; } return *this; } - ~my_shared_ptr() { - if(ref_count_ && 0 == dec_ref()) { delete ptr_; delete ref_count_; } - } - contained * get() { return ptr_; } - const contained * get() const { return ptr_; } + template + my_shared_ptr(const my_shared_ptr& s) :p(s.p), c(s.c) { if(c) ++*c; } - void swap(my_shared_ptr& rhs) // throw() - { - std::swap(ptr_, rhs.ptr_); - std::swap(ref_count_, rhs.ref_count_); - } + ~my_shared_ptr() { clear(); } - my_shared_ptr& operator=(const my_shared_ptr& rhs) { - my_shared_ptr tmp(rhs); - this->swap(tmp); - return *this; - } + void clear() + { + if(c) + { + if(*c==1) delete p; + if(!--*c) delete c; + } + c=0; p=0; + } - contained * operator->() { - return this->ptr_; - } + T* get() const { return (c)? p: 0; } + T* operator->() const { return get(); } + T& operator*() const { return *get(); } - // operator->, operator*, operator void*, use_count private: - void inc_ref() { - if(ref_count_) { ++(*ref_count_); } - } - - int dec_ref() { - return --(*ref_count_); - } - - contained * ptr_; - int * ref_count_; + T* p; + unsigned* c; }; +