http://www.aros.org AROS-Exec AROS-Exec Archives Power2People
kitty mascottop logo menu

AROS Application Development Manual -- Resource Tracking

Index

Advertencia

This document is not finished! It is highly likely that many parts are out-of-date, contain incorrect information, or are simply missing altogether. If you want to help rectify this, please contact us.

Introduction

Everyone talks about Resource Tracking (RT) but what is it anyway? RT means three things:

  1. The OS takes notes about allocated resources (e.g. memory, windows, libraries, devices, screens, etc.).
  2. The OS checks the usage of those resources (i.e. Did you open that window you want to render into? Is it still open? Is that a window anyway?)
  3. The OS closes resources if they are no longer used (either because your program crashed or because it exited without freeing them).

AROS implementation

The current implementation in AROS can do all three the things mentioned in the Introduction, but to enable it, you must make some modifications to your code. The only disadvantage of the current implementation is that the resources won't be freed if the program crashes.

  1. Add the following lines to your code. It should be the first thing seen by the compiler:

    #define ENABLE_RT  1
    

    If you replace the 1 by 0, then RT will be silently disabled.

  2. Add #include <aros/rt.h> after the last include from proto/

  3. Add RT_Init(); as the first command in main().

  4. Call RT_Exit() before you terminate your program.

  5. Recompile.

The advantages are that you will get errors if you try to access resources which you didn't allocate and that you will get a list of resources which you didn't free at the end of your program. All messages will contain the position in the code where the error happened (if available) and the position in the code where the resource was allocated (this is the reason why RT has to be compiled in. It could be built into the OS, too, but it would be hard to gather the information where an error occurred).

A good example about how to use RT and what it can do can be found in AROS/workbench/demos/rtdemo.c.

The following resources are tracked:

  • Memory in AllocMem(), FreeMem(),``AllocVec()``, and FreeVec();
  • MsgPorts in CreateMsgPort(), DeleteMsgPort(), CreatePort(), DeletePort(), and PutMsg();
  • Files in Open(), Close(), Read(), and Write(), and the buffers of Read() and Write();
  • Windows in OpenWindow(), OpenWindowTags(), OpenWindowTagList(), CloseWindow(), WindowToFront(), and WindowToBack();
  • Screens in OpenScreen(), OpenScreenTags(), OpenScreenTagList(), CloseScreen(), ScreenToFront(), and ScreenToBack(), and windows left open on the screen when calling CloseScreen().

Copyright © 1995-2024, The AROS Development Team. All rights reserved.
Amiga® is a trademark of Amiga Inc. All other trademarks belong to their respective owners.