在Java中,肯定對象大小的最佳方法是什麼? - In Java, what is the best way to determine the size of an object?

問題:

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


解決方案:

參考一: 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
相關文章
相關標籤/搜索