问题:
I have an application that reads a CSV file with piles of data rows. 我有一个应用程序,它读取带有大量数据行的CSV文件。 I give the user a summary of the number of rows based on types of data, but I want to make sure that I don't read in too many rows of data and cause OutOfMemoryError
s. 我根据数据类型为用户提供了行数的摘要,但我想确保不会读入太多数据行并导致OutOfMemoryError
。 Each row translates into an object. 每行转换为一个对象。 Is there an easy way to find out the size of that object programmatically? 有没有一种简便的方法以编程方式找出该对象的大小? Is there a reference that defines how large primitive types and object references are for a VM
? 是否有参考定义了VM
原始类型和对象参考有多大?
Right now, I have code that says read up to 32,000 rows , but I'd also like to have code that says read as many rows as possible until I've used 32MB of memory. 现在,我的代码可以读取多达32,000行 ,但我还想让代码显示尽可能多地读取行,直到使用32 MB内存为止。 Maybe that is a different question, but I'd still like to know. 也许这是一个不同的问题,但我仍然想知道。
解决方案:
参考一: https://stackoom.com/question/DcP/在Java中-确定对象大小的最佳方法是什么参考二: https://oldbug.net/q/DcP/In-Java-what-is-the-best-way-to-determine-the-size-of-an-object
来源:oschina
链接:https://my.oschina.net/u/4428122/blog/4404373