Skip to content

Access file as quickly as possible #49

Description

@cho934

Hi,

I'm trying to optimise the access to the file value0 for angle sensors, or IR sensors.
Because my motion system need these data every 5ms.

ifstream is currently used, I already managed some little change to decrease access time, but it's not enough (I opened the file once at the beginning, and during the loop, I just read).

Do you know how to be faster to retrieve the value (int) inside the file ?
Maybe using POSIX like described here
https://stackoverflow.com/questions/17925051/fast-textfile-reading-in-c
What do you think ?

You seem to use a cache, but I don't understand, Are you sure that the cache is really used using this current code in ev3dev.cpp ?

// A global cache of files.
std::ifstream& ifstream_cache(const std::string &path) {
  static lru_cache<std::string, std::ifstream> cache(FSTREAM_CACHE_SIZE);
  static std::mutex mx;

  std::lock_guard<std::mutex> lock(mx);
  return cache[path];
}

BR,
Cho.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions