OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ | 5 #ifndef BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ |
6 #define BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ | 6 #define BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <atomic> | 10 #include <atomic> |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 // operation, such as how much memory is currently used. This should be | 487 // operation, such as how much memory is currently used. This should be |
488 // called before such information is to be displayed or uploaded. | 488 // called before such information is to be displayed or uploaded. |
489 void UpdateTrackingHistograms(); | 489 void UpdateTrackingHistograms(); |
490 | 490 |
491 // While the above works much like malloc & free, these next methods provide | 491 // While the above works much like malloc & free, these next methods provide |
492 // an "object" interface similar to new and delete. | 492 // an "object" interface similar to new and delete. |
493 | 493 |
494 // Reserve space in the memory segment of the desired |size| and |type_id|. | 494 // Reserve space in the memory segment of the desired |size| and |type_id|. |
495 // A return value of zero indicates the allocation failed, otherwise the | 495 // A return value of zero indicates the allocation failed, otherwise the |
496 // returned reference can be used by any process to get a real pointer via | 496 // returned reference can be used by any process to get a real pointer via |
497 // the GetAsObject() or GetAsArray calls. | 497 // the GetAsObject() or GetAsArray calls. The actual allocated size may be |
| 498 // larger and will always be a multiple of 8 bytes (64 bits). |
498 Reference Allocate(size_t size, uint32_t type_id); | 499 Reference Allocate(size_t size, uint32_t type_id); |
499 | 500 |
500 // Allocate and construct an object in persistent memory. The type must have | 501 // Allocate and construct an object in persistent memory. The type must have |
501 // both (size_t) kExpectedInstanceSize and (uint32_t) kPersistentTypeId | 502 // both (size_t) kExpectedInstanceSize and (uint32_t) kPersistentTypeId |
502 // static constexpr fields that are used to ensure compatibility between | 503 // static constexpr fields that are used to ensure compatibility between |
503 // software versions. An optional size parameter can be specified to force | 504 // software versions. An optional size parameter can be specified to force |
504 // the allocation to be bigger than the size of the object; this is useful | 505 // the allocation to be bigger than the size of the object; this is useful |
505 // when the last field is actually variable length. | 506 // when the last field is actually variable length. |
506 template <typename T> | 507 template <typename T> |
507 T* New(size_t size) { | 508 T* New(size_t size) { |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 // share the same pointer then an allocation on one will amount to an | 861 // share the same pointer then an allocation on one will amount to an |
861 // allocation for all. | 862 // allocation for all. |
862 volatile std::atomic<Reference>* const reference_; | 863 volatile std::atomic<Reference>* const reference_; |
863 | 864 |
864 // No DISALLOW_COPY_AND_ASSIGN as it's okay to copy/move these objects. | 865 // No DISALLOW_COPY_AND_ASSIGN as it's okay to copy/move these objects. |
865 }; | 866 }; |
866 | 867 |
867 } // namespace base | 868 } // namespace base |
868 | 869 |
869 #endif // BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ | 870 #endif // BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ |
OLD | NEW |