optimized the header block size & fix the may comming leak for c binding
This commit is contained in:
parent
43cdeb8c17
commit
56c83f3895
|
|
@ -36,6 +36,8 @@ IP2R_API uint_t ip2region_create(ip2region_t ip2rObj, char *dbFile)
|
||||||
ip2rObj->dbHandler = fopen(dbFile, "rb");
|
ip2rObj->dbHandler = fopen(dbFile, "rb");
|
||||||
if ( ip2rObj->dbHandler == NULL )
|
if ( ip2rObj->dbHandler == NULL )
|
||||||
{
|
{
|
||||||
|
IP2R_FREE(ip2rObj->HeaderSip);
|
||||||
|
IP2R_FREE(ip2rObj->HeaderPtr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ typedef unsigned int uint_t;
|
||||||
typedef unsigned long ulong_t;
|
typedef unsigned long ulong_t;
|
||||||
|
|
||||||
#define INDEX_BLOCK_LENGTH 12
|
#define INDEX_BLOCK_LENGTH 12
|
||||||
#define TOTAL_HEADER_LENGTH 8192
|
#define TOTAL_HEADER_LENGTH 4096
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ip2region properties struct
|
* ip2region properties struct
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,8 @@ public class DbSearcher
|
||||||
if ( HeaderSip == null )
|
if ( HeaderSip == null )
|
||||||
{
|
{
|
||||||
raf.seek(8L); //pass the super block
|
raf.seek(8L); //pass the super block
|
||||||
byte[] b = new byte[dbConfig.getTotalHeaderSize()];
|
//byte[] b = new byte[dbConfig.getTotalHeaderSize()];
|
||||||
|
byte[] b = new byte[4096];
|
||||||
raf.readFully(b, 0, b.length);
|
raf.readFully(b, 0, b.length);
|
||||||
|
|
||||||
//fill the header
|
//fill the header
|
||||||
|
|
@ -291,6 +292,16 @@ public class DbSearcher
|
||||||
return binarySearch(Util.ip2long(ip));
|
return binarySearch(Util.ip2long(ip));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the db config
|
||||||
|
*
|
||||||
|
* @return DbConfig
|
||||||
|
*/
|
||||||
|
public DbConfig getDbConfig()
|
||||||
|
{
|
||||||
|
return dbConfig;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* close the db
|
* close the db
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined('INDEX_BLOCK_LENGTH') or define('INDEX_BLOCK_LENGTH', 12);
|
defined('INDEX_BLOCK_LENGTH') or define('INDEX_BLOCK_LENGTH', 12);
|
||||||
defined('TOTAL_HEADER_LENGTH') or define('TOTAL_HEADER_LENGTH', 8192);
|
defined('TOTAL_HEADER_LENGTH') or define('TOTAL_HEADER_LENGTH', 4096);
|
||||||
|
|
||||||
class Ip2Region
|
class Ip2Region
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue