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. 也許這是一個不一樣的問題,但我仍然想知道。 app