Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Is an array better or some other type?

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am collecting data every minute up to nine or more elements (double and strings, possibly) for 24 hours. I was planning on storing them in an array and then push out the oldest element and realized that array can be of only one type. This way I can access specific time elements as needed. The program runs constantly collecting data, everything will be stored in a database ultimately but every few minutes data will be pushed to another site. I thought having the extra database access would be painful for performance so I was looking at an in memory structure.

Here is my sample code which I have not completed yet but thought since I am still new to Java there might be some better approach instead of an array, maybe a stack, a queue, etc.

In this case, I am storing up to 10 minutes of data just to work through the process.

Any thoughts or direction would be appreciated.



Thanks
Mike
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lists have the advantage of being growable, but... I think you're overestimating the performance hit of a database. That said, I'd collect data and occasionally start up a thread to do the "send it somewhere else" bit, eliminating large memory usage, database access, data collection misses due to communication issues, etc. If the data needs to be reliably persisted, however, you'll want to either shove it into a file or DB.
 
Mike Bates
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David,

Thanks for the response. I will head down that road.

Thanks
Mike
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic