Memory limitation

This commit is contained in:
Victor Shcherb 2012-11-08 19:33:32 +01:00
parent 988ce0587e
commit 3e0c5d8466
8 changed files with 46 additions and 59 deletions

View file

@ -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;

View file

@ -11,7 +11,7 @@
<!-- by default it is 30. Value specified here overwrites all others
(don't specify here ! it is device dependent) -->
<attribute name="memoryLimitInMB" value="" />
<attribute name="nativeMemoryLimitInMB" value="75" />
<attribute name="nativeMemoryLimitInMB" value="" />
<!-- 1.2 Build A* graph in backward/forward direction (can affect results) -->
<!-- 0 - 2 ways, 1 - direct way, -1 - reverse way -->

View file

@ -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

View file

@ -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<RouteSegment> next = ctx->loadRouteSegment(x, y);
// 3. get intersected ways
if (next.get() != NULL) {

View file

@ -189,7 +189,7 @@ struct RoutingConfiguration {
distanceRecalculate = parseFloat("recalculateDistanceHelp", 10000) ;
}
RoutingConfiguration(vector<ROUTE_TRIPLE>& config, float initDirection = -360, int memLimit = 100) :
RoutingConfiguration(vector<ROUTE_TRIPLE>& config, float initDirection = -360, int memLimit = 48) :
memoryLimitation(memLimit), initialDirection(initDirection) {
for(int j = 0; j<config.size(); j++) {
ROUTE_TRIPLE r = config[j];
@ -442,7 +442,7 @@ struct RoutingContext {
}
void loadHeaderObjects(int64_t tileId) {
vector<SHARED_PTR<RoutingSubregionTile> > subregions = indexedSubregions[tileId];
vector<SHARED_PTR<RoutingSubregionTile> >& subregions = indexedSubregions[tileId];
bool gc = false;
for(int j = 0; j<subregions.size() && !gc; j++) {
if(!subregions[j]->isLoaded()) {
@ -514,7 +514,7 @@ struct RoutingContext {
uint32_t yloc = (y31+j*coordinatesShift) >> (31 - z);
int64_t tileId = (xloc << z) + yloc;
loadHeaders(xloc, yloc);
vector<SHARED_PTR<RoutingSubregionTile> > subregions = indexedSubregions[tileId];
vector<SHARED_PTR<RoutingSubregionTile> >& subregions = indexedSubregions[tileId];
for(int j = 0; j<subregions.size(); j++) {
if(subregions[j]->isLoaded()) {
UNORDERED(map)<int64_t, SHARED_PTR<RouteSegment> >::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<SHARED_PTR<RoutingSubregionTile> > subregions = indexedSubregions[tileId];
vector<SHARED_PTR<RoutingSubregionTile> >& subregions = indexedSubregions[tileId];
for(int j = 0; j<subregions.size(); j++) {
if(subregions[j]->isLoaded()) {
UNORDERED(map)<int64_t, SHARED_PTR<RouteSegment> >::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<SHARED_PTR<RoutingSubregionTile> > subregions = indexedSubregions[tileId];
vector<SHARED_PTR<RoutingSubregionTile> >& subregions = indexedSubregions[tileId];
UNORDERED(map)<int64_t, SHARED_PTR<RouteDataObject> > excludeDuplications;
SHARED_PTR<RouteSegment> original;
for(int j = 0; j<subregions.size(); j++) {

View file

@ -55,8 +55,12 @@
#if defined(ANDROID)
#include "shared_ptr.h"
#define SHARED_PTR my_shared_ptr
//# include <tr1/shared_ptr.h>
//# define SHARED_PTR std::tr1::shared_ptr
#elif defined(WINDOWS)
#else
//# include "shared_ptr.h"
//# define SHARED_PTR my_shared_ptr
# include <tr1/memory>
# define SHARED_PTR std::tr1::shared_ptr
#endif

View file

@ -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<ROUTE_TRIPLE> 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<RouteSegmentResult> r = searchRouteInternal(&c, false);
UNORDERED(map)<int64_t, int> indexes;
for (int t = 0; t< ienv->GetArrayLength(regions); t++) {

View file

@ -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 <typename contained>
class my_shared_ptr {
public:
my_shared_ptr() : ptr_(NULL), ref_count_(NULL) { }
my_shared_ptr(contained * p)
: ptr_(p), ref_count_(p ? new int : NULL)
{ inc_ref(); }
my_shared_ptr(const my_shared_ptr& rhs)
: ptr_(rhs.ptr_), ref_count_(rhs.ref_count_)
{ inc_ref(); }
~my_shared_ptr() {
if(ref_count_ && 0 == dec_ref()) { delete ptr_; delete ref_count_; }
}
contained * get() { return ptr_; }
const contained * get() const { return ptr_; }
void swap(my_shared_ptr& rhs) // throw()
// http://stackoverflow.com/questions/7792011/alternative-to-boostshared-ptr-in-an-embedded-environment
template<class T>
class my_shared_ptr
{
std::swap(ptr_, rhs.ptr_);
std::swap(ref_count_, rhs.ref_count_);
template<class U>
friend class my_shared_ptr;
public:
my_shared_ptr() :p(), c() {}
explicit my_shared_ptr(T* s) :p(s), c(new unsigned(1)) {}
my_shared_ptr(const my_shared_ptr& s) :p(s.p), c(s.c) { if(c) ++*c; }
my_shared_ptr& operator=(const my_shared_ptr& s)
{ if(this!=&s) { clear(); p=s.p; c=s.c; if(c) ++*c; } return *this; }
template<class U>
my_shared_ptr(const my_shared_ptr<U>& s) :p(s.p), c(s.c) { if(c) ++*c; }
~my_shared_ptr() { clear(); }
void clear()
{
if(c)
{
if(*c==1) delete p;
if(!--*c) delete c;
}
c=0; p=0;
}
my_shared_ptr& operator=(const my_shared_ptr& rhs) {
my_shared_ptr tmp(rhs);
this->swap(tmp);
return *this;
}
T* get() const { return (c)? p: 0; }
T* operator->() const { return get(); }
T& operator*() const { return *get(); }
contained * operator->() {
return this->ptr_;
}
// 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;
};