Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7635975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:33:39+00:00 2026-05-31T07:33:39+00:00

Consider a class with a static factory method, which gets a CSV (or TSV)

  • 0

Consider a class with a static factory method, which gets a CSV (or TSV) line as input (Variable names renamed for convenience):

String[] fields=StringUtils.split(tsvLine, '\t');
return new MYObject(
    Integer.parseInt(fields[0]),
    StringUtils.strip(fields[1], "\"").intern(), // Many duplicates
    StringUtils.strip(fields[2], "\""),          // Unique
    StringUtils.strip(fields[4], "\"").intern(), // Many duplicates
    Double.parseDouble(fields[7]),
    Double.parseDouble(fields[6])); 

This method parses around 5 million records, from a file ~500 MB in size. In order to save memory, I save the three Strings concatenated:

I’ve tried the following optimization:

public MyObject(int i1, String str0, String str1, String str2, 
                double d1, double d2)
{
...
this.tsvStrings = (str0+'\t'+str1+'\t'+str2).toCharArray();
...
}

(These are split, of course, in the appropriate getters and setters).

The process size is still well over 1GB, although most of its contents is ignored. What’s the best way to optimize this? Am I keeping unnecessary references?

EDIT: str0 and str2 have duplicates, str1 is unique.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:33:40+00:00Added an answer on May 31, 2026 at 7:33 am

    If you have a file which is encoded with UTF-8, it will use about double that in memory by default (as it uses UTF-16 in memory). That is because String and StringBuilder uses two bytes per character (for most characters)

    If you manipulate that data, you can need double or more that amount of memory.

    You can make the processing more compact using memory mapped files, and plain bytes etc, but given 16 GB of memory costs about £100 it may be a better use of your time to use more memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: class Program { static void Main(string[] args) { Department deathStar
Consider this snippet of code: public static class MatchCollectionExtensions { public static IEnumerable<T> AsEnumerable<T>(this
Consider this sample class, class TargetClass { private static String SENSITIVE_DATA = sw0rdfish; private
Consider the following code: using System; namespace ConsoleApplication2 { class Program { static void
Consider the following code: public class MyClass { public static string MyStaticMethod() { //string
Consider the following Java class: public class Foo { public static void doStuff() {
Please consider the following java source: package com.stackoverflow; public class CondSpeed { private static
Consider the following code: class Program { static void Main(string[] args) { try {
Consider this code snippet: class Program { static void Main(string[] args) { Console.WriteLine(Test().ToString()); }
Consider this code snippet: public static class ApplicationContext { private static Func<TService> Uninitialized<TService>() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.