[Gambas-user] Size of a result in memory
Tobias Boege
taboege at gmail.com
Wed Oct 18 11:05:05 CEST 2017
On Wed, 18 Oct 2017, Christof Thalhofer wrote:
> Hello,
>
> is there a simple way to get the size of a db result in memory?
>
> If I use:
>
> Object.SizeOf(resultobj)
>
> I get a very small count of bytes, way too small for the real size of
> all the tuples contained by the resultobject.
>
>
Object.SizeOf() gives more of a static size of an object. Have a look at
the implementation:
767 BEGIN_METHOD(Object_SizeOf, GB_OBJECT object)
768
769 void *object = VARG(object);
770
771 if (check_null(object))
772 return;
773
774 GB_ReturnInteger(CLASS_sizeof(OBJECT_class(object)));
775
776 END_METHOD
It returns the size of the *class* of the object. Native classes in Gambas
manage their memory more or less by themselves, especially if they interact
with external libraries, and they don't keep track of the dynamic memory
they use.
So, you can't get the information you want, but the good news is that this
information wouldn't have helped you either way. Unless your DBMS is made
for tiny amounts of data, you shouldn't expect the dynamic memory allocated
by the Result object to be indicative of the size of the query result.
A Result object is usually just a small (almost fixed-size) object that is
associated to a database connection and a query and allows you to fetch or
navigate through the tuples. The DBMS loads the data on-demand, because
you would expect that the entirety of a database result would not fit into
your memory anyway.
You should talk to the DBMS. If that doesn't know how big the result is,
then really nobody does. But I suppose that this calculation is expensive.
Regards,
Tobi
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the User
mailing list