能源管控程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.1 KiB

2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # ArduinoQueue
  2. [![Build Status](https://travis-ci.org/EinarArnason/ArduinoQueue.svg?branch=dev)](https://travis-ci.org/EinarArnason/ArduinoQueue)
  3. A lightweight linked list type queue implementation, meant for microcontrollers.
  4. Written as a C++ template class.
  5. ## Constructors
  6. Creates a queue up to _<maximum_number_of_items>_ items:
  7. ```C++
  8. ArduinoQueue<T> intQueue(maximum_number_of_items);
  9. ```
  10. Creates a queue up to _<maximum_size_in_bytes>_ bytes:
  11. ```C++
  12. ArduinoQueue<T> intQueue(0, maximum_size_in_bytes);
  13. ```
  14. Creates a queue up to _<maximum_number_of_items>_ items or _<maximum_size_in_bytes>_ bytes, whatever comes first:
  15. ```C++
  16. ArduinoQueue<T> intQueue(maximum_number_of_items, maximum_size_in_bytes);
  17. ```
  18. ## How to use
  19. Include the header file on your code:
  20. ```C++
  21. #include <ArduinoQueue.h>
  22. ```
  23. Then create the queue according to your needs, examples:
  24. - To create a queue of **_int_**, capable of holding 20 items:
  25. ```C++
  26. ArduinoQueue<int> intQueue(20);
  27. ```
  28. - To create a queue of **_int_**, capable of holding 20 items or a maximum size of 10 bytes _(whatever comes first)_:
  29. ```C++
  30. ArduinoQueue<int> intQueue(20, 10);
  31. ```
  32. - To create a queue of your **_defined structure_**, capable of holding 50 items:
  33. ```C++
  34. struct car {
  35. char brand[10];
  36. char model[10];
  37. int nr_doors;
  38. };
  39. ArduinoQueue<car> myCarsQueue(50);
  40. ```
  41. Finally use the following functions:
  42. ```C++
  43. intQueue.enqueue(1); // Adds number 1 to the queue
  44. intQueue.enqueue(123); // Adds number 123 to the queue
  45. int number = intQueue.dequeue(); // Will return number 1 and remove it from the queue
  46. int number = intQueue.getHead(); // Will return number 123 but leave it still in the queue
  47. int number = intQueue.dequeue(); // Will return number 123 and remove it from the queue
  48. ```
  49. You can use also the following functions to get more queue properties:
  50. ```C++
  51. bool state = intQueue.isEmpty(); // Returns true if the queue is empty, false otherwise
  52. bool state = intQueue.isFull(); // Returns true if the queue is full, false otherwise
  53. unsigned int n = intQueue.itemCount(); // Returns the number of items currently on the queue
  54. unsigned int n = intQueue.itemSize(); // Returns the size of the item being stored (bytes)
  55. unsigned int n = intQueue.maxQueueSize(); // Returns the maximum possible size of the queue (items)*
  56. unsigned int n = intQueue.maxMemorySize(); // Returns the maximum possible size of the queue (bytes)*
  57. ```
  58. ## Thread safety
  59. This library is **not** thread safe. Mutexes are often hardware specific on the way they are optimized to operate. So for the sake of performance and portability, it is left out.
  60. ## Memory safety
  61. The memory for the queue nodes are dynamically allocated. Note that while the Queue class cleans up the nodes in memory after destructor or dequeue is called, it keeps a copy of the item being queued. So for example if you are queuing pointers, you will need to keep track of the memory behind them.
  62. ## Performance
  63. CPU: Intel i7-6500U
  64. RAM: DDR4L
  65. Benchmark result (1000 samples):
  66. Enqueued 1000000 ints in average 0.018749799 seconds
  67. Dequeued 1000000 ints in average 0.016496857 seconds
  68. Allocated 15.2588 MB (16 bytes per item)