mirror of https://github.com/postgres/postgres
for the last two releases. Modified Files: jdbc/org/postgresql/Driver.java.in jdbc/org/postgresql/PG_Stream.java Removed Files: jdbc/org/postgresql/core/BytePoolDim1.java jdbc/org/postgresql/core/BytePoolDim2.java jdbc/org/postgresql/core/MemoryPool.java jdbc/org/postgresql/core/ObjectPool.java jdbc/org/postgresql/core/SimpleObjectPool.javaREL7_3_STABLE
parent
c43760a714
commit
f736fdb022
@ -1,100 +0,0 @@ |
||||
package org.postgresql.core; |
||||
|
||||
/* |
||||
* A simple and efficient class to pool one dimensional byte arrays |
||||
* of different sizes. |
||||
*/ |
||||
public class BytePoolDim1 |
||||
{ |
||||
/* |
||||
* The maximum size of the array we manage. |
||||
*/ |
||||
int maxsize = 256; |
||||
/* |
||||
* The pools not currently in use |
||||
*/ |
||||
ObjectPool notusemap[] = new ObjectPool[maxsize + 1]; |
||||
/* |
||||
* The pools currently in use |
||||
*/ |
||||
ObjectPool inusemap[] = new ObjectPool[maxsize + 1]; |
||||
/* |
||||
* |
||||
*/ |
||||
byte binit[][] = new byte[maxsize + 1][0]; |
||||
|
||||
/* |
||||
* Construct a new pool |
||||
*/ |
||||
public BytePoolDim1() |
||||
{ |
||||
for (int i = 0; i <= maxsize; i++) |
||||
{ |
||||
binit[i] = new byte[i]; |
||||
inusemap[i] = new SimpleObjectPool(); |
||||
notusemap[i] = new SimpleObjectPool(); |
||||
} |
||||
} |
||||
|
||||
/* |
||||
* Allocate a byte[] of a specified size and put it in the pool. If it's |
||||
* larger than maxsize then it is not pooled. |
||||
* @return the byte[] allocated |
||||
*/ |
||||
public byte[] allocByte(int size) |
||||
{ |
||||
// for now until the bug can be removed
|
||||
return new byte[size]; |
||||
/* |
||||
// Don't pool if >maxsize
|
||||
if (size > maxsize){ |
||||
return new byte[size]; |
||||
} |
||||
|
||||
ObjectPool not_usel = notusemap[size]; |
||||
ObjectPool in_usel = inusemap[size]; |
||||
byte b[] = null; |
||||
|
||||
// Fetch from the unused pool if available otherwise allocate a new
|
||||
// now array
|
||||
if (!not_usel.isEmpty()) { |
||||
Object o = not_usel.remove(); |
||||
b = (byte[]) o; |
||||
} else |
||||
b = new byte[size]; |
||||
in_usel.add(b); |
||||
|
||||
return b; |
||||
*/ |
||||
} |
||||
|
||||
/* |
||||
* Release an array |
||||
* @param b byte[] to release |
||||
*/ |
||||
public void release(byte[] b) |
||||
{ |
||||
// If it's larger than maxsize then we don't touch it
|
||||
if (b.length > maxsize) |
||||
return; |
||||
|
||||
ObjectPool not_usel = notusemap[b.length]; |
||||
ObjectPool in_usel = inusemap[b.length]; |
||||
|
||||
in_usel.remove(b); |
||||
not_usel.add(b); |
||||
} |
||||
|
||||
/* |
||||
* Deallocate all |
||||
* @deprecated Real bad things happen if this is called! |
||||
*/ |
||||
public void deallocate() |
||||
{ |
||||
//for(int i = 0; i <= maxsize; i++){
|
||||
// notusemap[i].addAll(inusemap[i]);
|
||||
// inusemap[i].clear();
|
||||
//}
|
||||
} |
||||
} |
||||
|
@ -1,69 +0,0 @@ |
||||
package org.postgresql.core; |
||||
|
||||
public class BytePoolDim2 |
||||
{ |
||||
int maxsize = 32; |
||||
ObjectPool notusemap[] = new ObjectPool[maxsize + 1]; |
||||
ObjectPool inusemap[] = new ObjectPool[maxsize + 1]; |
||||
|
||||
public BytePoolDim2() |
||||
{ |
||||
for (int i = 0; i <= maxsize; i++) |
||||
{ |
||||
inusemap[i] = new SimpleObjectPool(); |
||||
notusemap[i] = new SimpleObjectPool(); |
||||
} |
||||
} |
||||
|
||||
public byte[][] allocByte(int size) |
||||
{ |
||||
// For now until the bug can be removed
|
||||
return new byte[size][0]; |
||||
/* |
||||
if (size > maxsize){ |
||||
return new byte[size][0]; |
||||
} |
||||
ObjectPool not_usel = notusemap[size]; |
||||
ObjectPool in_usel = inusemap[size]; |
||||
|
||||
byte b[][] = null; |
||||
|
||||
if (!not_usel.isEmpty()) { |
||||
Object o = not_usel.remove(); |
||||
b = (byte[][]) o; |
||||
} else |
||||
b = new byte[size][0]; |
||||
in_usel.add(b); |
||||
return b; |
||||
*/ |
||||
} |
||||
|
||||
public void release(byte[][] b) |
||||
{ |
||||
if (b.length > maxsize) |
||||
{ |
||||
return; |
||||
} |
||||
ObjectPool not_usel = notusemap[b.length]; |
||||
ObjectPool in_usel = inusemap[b.length]; |
||||
|
||||
in_usel.remove(b); |
||||
not_usel.add(b); |
||||
} |
||||
|
||||
/* |
||||
* Deallocate the object cache. |
||||
* PM 17/01/01: Commented out this code as it blows away any hope of |
||||
* multiple queries on the same connection. I'll redesign the allocation |
||||
* code to use some form of Statement context, so the buffers are per |
||||
* Statement and not per Connection/PG_Stream as it is now. |
||||
*/ |
||||
public void deallocate() |
||||
{ |
||||
//for(int i = 0; i <= maxsize; i++){
|
||||
// notusemap[i].addAll(inusemap[i]);
|
||||
// inusemap[i].clear();
|
||||
//}
|
||||
} |
||||
} |
||||
|
@ -1,19 +0,0 @@ |
||||
package org.postgresql.core; |
||||
|
||||
/* |
||||
* This interface defines the methods to access the memory pool classes. |
||||
*/ |
||||
public interface MemoryPool |
||||
{ |
||||
/* |
||||
* Allocate an array from the pool |
||||
* @return byte[] allocated |
||||
*/ |
||||
public byte[] allocByte(int size); |
||||
|
||||
/* |
||||
* Frees an object back to the pool |
||||
* @param o Object to release |
||||
*/ |
||||
public void release(Object o); |
||||
} |
@ -1,49 +0,0 @@ |
||||
package org.postgresql.core; |
||||
|
||||
/* |
||||
* This interface defines methods needed to implement a simple object pool. |
||||
* There are two known classes that implement this, one for jdk1.1 and the |
||||
* other for jdk1.2+ |
||||
*/ |
||||
|
||||
public interface ObjectPool |
||||
{ |
||||
/* |
||||
* Adds an object to the pool |
||||
* @param o Object to add |
||||
*/ |
||||
public void add(Object o); |
||||
|
||||
/* |
||||
* Removes an object from the pool |
||||
* @param o Object to remove |
||||
*/ |
||||
public void remove(Object o); |
||||
|
||||
/* |
||||
* Removes the top object from the pool |
||||
* @return Object from the top. |
||||
*/ |
||||
public Object remove(); |
||||
|
||||
/* |
||||
* @return true if the pool is empty |
||||
*/ |
||||
public boolean isEmpty(); |
||||
|
||||
/* |
||||
* @return the number of objects in the pool |
||||
*/ |
||||
public int size(); |
||||
|
||||
/* |
||||
* Adds all objects in one pool to this one |
||||
* @param pool The pool to take the objects from |
||||
*/ |
||||
public void addAll(ObjectPool pool); |
||||
|
||||
/* |
||||
* Clears the pool of all objects |
||||
*/ |
||||
public void clear(); |
||||
} |
@ -1,106 +0,0 @@ |
||||
package org.postgresql.core; |
||||
|
||||
/* |
||||
* A simple and fast object pool implementation that can pool objects |
||||
* of any type. This implementation is not thread safe, it is up to the users |
||||
* of this class to assure thread safety. |
||||
*/ |
||||
|
||||
public class SimpleObjectPool implements ObjectPool |
||||
{ |
||||
// This was originally in PG_Stream but moved out to fix the major problem
|
||||
// where more than one query (usually all the time) overwrote the results
|
||||
// of another query.
|
||||
int cursize = 0; |
||||
int maxsize = 16; |
||||
Object arr[] = new Object[maxsize]; |
||||
|
||||
/* |
||||
* Adds an object to the pool |
||||
* @param o Object to add |
||||
*/ |
||||
public void add(Object o) |
||||
{ |
||||
if (cursize >= maxsize) |
||||
{ |
||||
Object newarr[] = new Object[maxsize * 2]; |
||||
System.arraycopy(arr, 0, newarr, 0, maxsize); |
||||
maxsize = maxsize * 2; |
||||
arr = newarr; |
||||
} |
||||
arr[cursize++] = o; |
||||
} |
||||
|
||||
/* |
||||
* Removes the top object from the pool |
||||
* @return Object from the top. |
||||
*/ |
||||
public Object remove() |
||||
{ |
||||
return arr[--cursize]; |
||||
} |
||||
|
||||
/* |
||||
* Removes the given object from the pool |
||||
* @param o Object to remove |
||||
*/ |
||||
public void remove(Object o) |
||||
{ |
||||
int p = 0; |
||||
while (p < cursize && !arr[p].equals(o)) |
||||
p++; |
||||
if (arr[p].equals(o)) |
||||
{ |
||||
// This should be ok as there should be no overlap conflict
|
||||
System.arraycopy(arr, p + 1, arr, p, cursize - p); |
||||
cursize--; |
||||
} |
||||
} |
||||
|
||||
/* |
||||
* @return true if the pool is empty |
||||
*/ |
||||
public boolean isEmpty() |
||||
{ |
||||
return cursize == 0; |
||||
} |
||||
|
||||
/* |
||||
* @return the number of objects in the pool |
||||
*/ |
||||
public int size() |
||||
{ |
||||
return cursize; |
||||
} |
||||
|
||||
/* |
||||
* Adds all objects in one pool to this one |
||||
* @param pool The pool to take the objects from |
||||
*/ |
||||
public void addAll(ObjectPool p) |
||||
{ |
||||
SimpleObjectPool pool = (SimpleObjectPool)p; |
||||
|
||||
int srcsize = pool.size(); |
||||
if (srcsize == 0) |
||||
return; |
||||
int totalsize = srcsize + cursize; |
||||
if (totalsize > maxsize) |
||||
{ |
||||
Object newarr[] = new Object[totalsize * 2]; |
||||
System.arraycopy(arr, 0, newarr, 0, cursize); |
||||
maxsize = maxsize = totalsize * 2; |
||||
arr = newarr; |
||||
} |
||||
System.arraycopy(pool.arr, 0, arr, cursize, srcsize); |
||||
cursize = totalsize; |
||||
} |
||||
|
||||
/* |
||||
* Clears the pool of all objects |
||||
*/ |
||||
public void clear() |
||||
{ |
||||
cursize = 0; |
||||
} |
||||
} |
Loading…
Reference in new issue