Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Designing a Cross-Platform API for Application Utilities #2

Open
MrManiacc opened this issue Aug 28, 2023 · 0 comments
Open

Designing a Cross-Platform API for Application Utilities #2

MrManiacc opened this issue Aug 28, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@MrManiacc
Copy link
Owner

Issue: Designing a Cross-Platform API for Application Utilities


Description:

Our project currently leverages POSIX utilities like pthread and other related functionalities. While this provides great features and compatibility for UNIX-based systems, it poses a dependency challenge for Windows users who are required to have mingw installed. The objective is to design and implement a platform-agnostic API that offers a consistent interface across multiple platforms.


Objectives:

  1. Platform Independence: The API should abstract away platform-specific details, allowing developers to write code once and run it on multiple platforms without modification.
  2. Core Utilities Abstraction: Key utilities like memory management, process management, and file management should be covered.
  3. Performance: The abstraction layer should introduce minimal performance overhead.
  4. Extensibility: The API should be designed in a modular manner, allowing for easy addition of more utilities or features in the future.

Challenges:

  1. Differing Semantics: Different platforms may have different ways of handling processes, files, or memory, even if they offer similar functionalities.
  2. Error Handling: Error codes and their meanings can vary across platforms. A unified error handling mechanism is needed.
  3. Performance Overhead: Introducing an abstraction layer can potentially introduce performance bottlenecks if not carefully designed.

Potential Solutions:

  1. Layered Design:

    • Low-level Layer: This layer interacts directly with the platform-specific APIs. Separate implementations for each platform will reside here.
    • High-level Layer: This is the API that the rest of the application will use. It interacts with the low-level layer and presents a unified interface.
  2. Feature Flags: During compilation, use feature flags to decide which platform-specific implementation should be compiled. This ensures that the application only includes what it needs, reducing bloat and potential errors.

  3. Unified Error Handling: Design a set of error codes that the API can return. The low-level layer will map platform-specific error codes to these unified codes.

  4. Performance Testing: Regularly benchmark the performance of the API on different platforms to ensure that the abstraction isn't introducing significant overhead.


Implementation Suggestions:

  1. Start with Memory Management:

    • Design functions for allocation, deallocation, and querying memory. Under the hood, these can use malloc/free on UNIX systems, and the appropriate counterparts on other platforms.
  2. Process Management:

    • Design functions to start, stop, and query processes. These should abstract away the differences between fork/exec on UNIX and CreateProcess on Windows, for example.
  3. File Management:

    • Design functions for file operations like open, read, write, and close. Ensure that path handling is consistent across platforms.
  4. Documentation:

    • For every function in the API, provide clear documentation on its behavior, return values, and error codes. This will be crucial for developers using the API.
  5. Community Feedback:

    • As the API is developed, gather feedback from the community or other developers on its usability and performance. Their insights can be invaluable in refining the API.

@MrManiacc MrManiacc added this to Vos Aug 28, 2023
@MrManiacc MrManiacc moved this to Todo in Vos Aug 28, 2023
@MrManiacc MrManiacc self-assigned this Aug 28, 2023
@MrManiacc MrManiacc added the enhancement New feature or request label Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

1 participant