VirtualBox

source: vbox/trunk/include/iprt/strcache.h@ 66599

Last change on this file since 66599 was 62473, checked in by vboxsync, 8 years ago

(C) 2016

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1/* $Id: strcache.h 62473 2016-07-22 18:15:28Z vboxsync $ */
2/** @file
3 * IPRT - String Cache, stub implementation.
4 */
5
6/*
7 * Copyright (C) 2009-2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef ___iprt_strcache_h
28#define ___iprt_strcache_h
29
30#include <iprt/types.h>
31
32RT_C_DECLS_BEGIN
33
34
35/**
36 * Create a new string cache.
37 *
38 * @returns IPRT status code
39 *
40 * @param phStrCache Where to return the string cache handle.
41 * @param pszName The name of the cache (for debug purposes).
42 */
43RTDECL(int) RTStrCacheCreate(PRTSTRCACHE phStrCache, const char *pszName);
44
45
46/**
47 * Destroys a string cache.
48 *
49 * This will cause all strings in the cache to be released and thus become
50 * invalid.
51 *
52 * @returns IPRT status.
53 *
54 * @param hStrCache Handle to the string cache. The nil and default
55 * handles are ignored quietly (VINF_SUCCESS).
56 */
57RTDECL(int) RTStrCacheDestroy(RTSTRCACHE hStrCache);
58
59
60/**
61 * Enters a string into the cache.
62 *
63 * @returns Pointer to a read-only copy of the string.
64 *
65 * @param hStrCache Handle to the string cache.
66 * @param pchString Pointer to a string. This does not need to be
67 * zero terminated, but must not contain any zero
68 * characters.
69 * @param cchString The number of characters (bytes) to enter.
70 *
71 * @remarks It is implementation dependent whether the returned string pointer
72 * differs when entering the same string twice.
73 */
74RTDECL(const char *) RTStrCacheEnterN(RTSTRCACHE hStrCache, const char *pchString, size_t cchString);
75
76/**
77 * Enters a string into the cache.
78 *
79 * @returns Pointer to a read-only copy of the string.
80 *
81 * @param hStrCache Handle to the string cache.
82 * @param psz Pointer to a zero terminated string.
83 *
84 * @remarks See RTStrCacheEnterN.
85 */
86RTDECL(const char *) RTStrCacheEnter(RTSTRCACHE hStrCache, const char *psz);
87
88
89/**
90 * Enters a string into the cache in lower cased form.
91 *
92 * @returns Pointer to a read-only lower cased copy of the string.
93 *
94 * @param hStrCache Handle to the string cache.
95 * @param pchString Pointer to a string. This does not need to be
96 * zero terminated, but must not contain any zero
97 * characters.
98 * @param cchString The number of characters (bytes) to enter.
99 *
100 * @remarks It is implementation dependent whether the returned string pointer
101 * differs when entering the same string twice.
102 */
103RTDECL(const char *) RTStrCacheEnterLowerN(RTSTRCACHE hStrCache, const char *pchString, size_t cchString);
104
105/**
106 * Enters a string into the cache in lower cased form.
107 *
108 * @returns Pointer to a read-only lower cased copy of the string.
109 *
110 * @param hStrCache Handle to the string cache.
111 * @param psz Pointer to a zero terminated string.
112 *
113 * @remarks See RTStrCacheEnterN.
114 */
115RTDECL(const char *) RTStrCacheEnterLower(RTSTRCACHE hStrCache, const char *psz);
116
117
118/**
119 * Retains a reference to a string.
120 *
121 * @returns The new reference count. UINT32_MAX is returned if the string
122 * pointer is invalid.
123 */
124RTDECL(uint32_t) RTStrCacheRetain(const char *psz);
125
126/**
127 * Releases a reference to a string.
128 *
129 * @returns The new reference count.
130 * UINT32_MAX is returned if the string pointer is invalid.
131 *
132 * @param hStrCache Handle to the string cache. NIL is NOT allowed.
133 * @param psz Pointer to a cached string.
134 */
135RTDECL(uint32_t) RTStrCacheRelease(RTSTRCACHE hStrCache, const char *psz);
136
137/**
138 * Gets the string length of a cache entry.
139 *
140 * @returns The string length. 0 if the string is invalid (asserted).
141 *
142 * @param psz Pointer to a cached string.
143 */
144RTDECL(size_t) RTStrCacheLength(const char *psz);
145
146
147/**
148 * Gets cache statistics.
149 *
150 * All parameters, except @a hStrCache, are optional and can be NULL.
151 *
152 * @returns Number of strings, UINT32_MAX on failure (or not supported).
153 * @param hStrCache Handle to the string cache.
154 * @param pcbStrings The number of string bytes (including
155 * terminators) .
156 * @param pcbChunks Amount of memory we've allocated for the
157 * internal allocator.
158 * @param pcbBigEntries Amount of memory we've allocated off the heap
159 * for really long strings that doesn't fit in the
160 * internal allocator.
161 * @param pcHashCollisions Number of hash table insert collisions.
162 * @param pcHashCollisions2 Number of hash table secondary insert
163 * collisions.
164 * @param pcHashInserts Number of hash table inserts.
165 * @param pcRehashes The number of rehashes.
166 *
167 * @remarks This is not a stable interface as it needs to reflect the cache
168 * implementation.
169 */
170RTDECL(uint32_t) RTStrCacheGetStats(RTSTRCACHE hStrCache, size_t *pcbStrings, size_t *pcbChunks, size_t *pcbBigEntries,
171 uint32_t *pcHashCollisions, uint32_t *pcHashCollisions2, uint32_t *pcHashInserts,
172 uint32_t *pcRehashes);
173
174/**
175 * Indicates whether this a real string cache or a cheap place holder.
176 *
177 * A real string cache will return the same address when a string is added
178 * multiple times.
179 *
180 * @returns true / false.
181 */
182RTDECL(bool) RTStrCacheIsRealImpl(void);
183
184
185RT_C_DECLS_END
186
187#endif
188
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette