本文整理汇总了C++中osd_malloc_array函数的典型用法代码示例。如果您正苦于以下问题:C++ osd_malloc_array函数的具体用法?C++ osd_malloc_array怎么用?C++ osd_malloc_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了osd_malloc_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: osd_malloc
static osd_shared_mem *osd_sharedmem_alloc(const char *path, int create, size_t size)
{
int fd;
osd_shared_mem *os_shmem = (osd_shared_mem *) osd_malloc(sizeof(osd_shared_mem));
if (create)
{
char *buf = (char *) osd_malloc_array(size);
memset(buf,0, size);
fd = open(path, O_RDWR | O_CREAT, S_IRWXU);
write(fd, buf, size);
os_shmem->creator = 1;
}
else
{
fd = open(path, O_RDWR);
if (fd == -1)
{
osd_free(os_shmem);
return NULL;
}
os_shmem->creator = 0;
}
os_shmem->fn = (char *) osd_malloc_array(strlen(path)+1);
strcpy(os_shmem->fn, path);
assert(fd != -1);
os_shmem->ptr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
os_shmem->size = size;
close(fd);
return os_shmem;
}
示例2: osd_free
text_buffer *text_buffer_alloc(UINT32 bytes, UINT32 lines)
{
text_buffer *text;
/* allocate memory for the text buffer object */
text = (text_buffer *)osd_malloc(sizeof(*text));
if (!text)
return NULL;
/* allocate memory for the buffer itself */
text->buffer = (char *)osd_malloc_array(bytes);
if (!text->buffer)
{
osd_free(text);
return NULL;
}
/* allocate memory for the lines array */
text->lineoffs = (INT32 *)osd_malloc_array(lines * sizeof(text->lineoffs[0]));
if (!text->lineoffs)
{
osd_free(text->buffer);
osd_free(text);
return NULL;
}
/* initialize the buffer description */
text->bufsize = bytes;
text->linesize = lines;
text_buffer_clear(text);
return text;
}
示例3: osd_get_full_path
file_error osd_get_full_path(char **dst, const char *path)
{
file_error err;
char path_buffer[512];
err = FILERR_NONE;
if (getcwd(path_buffer, 511) == NULL)
{
printf("osd_get_full_path: failed!\n");
err = FILERR_FAILURE;
}
else
{
*dst = (char *)osd_malloc_array(strlen(path_buffer)+strlen(path)+3);
// if it's already a full path, just pass it through
if (path[0] == '/')
{
strcpy(*dst, path);
}
else
{
sprintf(*dst, "%s%s%s", path_buffer, PATH_SEPARATOR, path);
}
}
return err;
}
示例4: osd_malloc_array
void *malloc_array_file_line(size_t size, const char *file, int line)
{
// allocate the memory and fail if we can't
void *ret = osd_malloc_array(size);
memset(ret, 0, size);
return ret;
}
示例5: osd_malloc_array
void *malloc_file_line(size_t size, const char *file, int line, bool array, bool throw_on_fail, bool clear)
{
// allocate the memory and fail if we can't
void *result = array ? osd_malloc_array(size) : osd_malloc(size);
if (result == nullptr)
{
fprintf(stderr, "Failed to allocate %d bytes (%s:%d)\n", UINT32(size), file, line);
osd_break_into_debugger("Failed to allocate RAM");
if (throw_on_fail)
throw std::bad_alloc();
return nullptr;
}
// zap the memory if requested
if (clear)
memset(result, 0, size);
else
{
#if !__has_feature(memory_sanitizer) && defined(INITIALIZE_ALLOCATED_MEMORY) && !defined(MAME_DEBUG_FAST)
memset(result, 0xdd, size);
#endif
}
// add a new entry
memory_entry::allocate(size, result, file, line, array);
return result;
}
示例6: defined
osd_directory_entry *osd_stat(const char *path)
{
int err;
osd_directory_entry *result = NULL;
#if defined(SDLMAME_NO64BITIO) || defined(SDLMAME_BSD) || defined(SDLMAME_DARWIN) || defined(SDLMAME_OS2)
struct stat st;
#else
struct stat64 st;
#endif
#if defined(SDLMAME_NO64BITIO) || defined(SDLMAME_BSD) || defined(SDLMAME_DARWIN) || defined(SDLMAME_OS2)
err = stat(path, &st);
#else
err = stat64(path, &st);
#endif
if( err == -1) return NULL;
// create an osd_directory_entry; be sure to make sure that the caller can
// free all resources by just freeing the resulting osd_directory_entry
result = (osd_directory_entry *) osd_malloc_array(sizeof(*result) + strlen(path) + 1);
strcpy(((char *) result) + sizeof(*result), path);
result->name = ((char *) result) + sizeof(*result);
result->type = S_ISDIR(st.st_mode) ? ENTTYPE_DIR : ENTTYPE_FILE;
result->size = (UINT64)st.st_size;
return result;
}
示例7:
char *core_strdup(const char *str)
{
char *cpy = NULL;
if (str != NULL)
{
cpy = (char *)osd_malloc_array(strlen(str) + 1);
if (cpy != NULL)
strcpy(cpy, str);
}
return cpy;
}
示例8: osd_malloc_array
static char *build_full_path(const char *path, const char *file)
{
char *ret = (char *) osd_malloc_array(strlen(path)+strlen(file)+2);
char *p = ret;
strcpy(p, path);
p += strlen(path);
*p++ = PATHSEPCH;
strcpy(p, file);
return ret;
}
示例9: MultiByteToWideChar
WCHAR *wstring_from_utf8(const char *utf8string)
{
int char_count;
WCHAR *result;
// convert MAME string (UTF-8) to UTF-16
char_count = MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, NULL, 0);
result = (WCHAR *)osd_malloc_array(char_count * sizeof(*result));
if (result != NULL)
MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, result, char_count);
return result;
}
示例10: WideCharToMultiByte
char *utf8_from_wstring(const WCHAR *wstring)
{
int char_count;
char *result;
// convert UTF-16 to MAME string (UTF-8)
char_count = WideCharToMultiByte(CP_UTF8, 0, wstring, -1, NULL, 0, NULL, NULL);
result = (char *)osd_malloc_array(char_count * sizeof(*result));
if (result != NULL)
WideCharToMultiByte(CP_UTF8, 0, wstring, -1, result, char_count, NULL, NULL);
return result;
}
示例11: osd_get_full_path
file_error osd_get_full_path(char **dst, const char *path)
{
// derive the full path of the file in an allocated string
// for now just fake it since we don't presume any underlying file system
*dst = NULL;
if (path != NULL)
{
*dst = (char *)osd_malloc_array(strlen(path) + 1);
if (*dst != NULL)
strcpy(*dst, path);
}
return FILERR_NONE;
}
示例12: acquire_lock
memory_entry *memory_entry::allocate(size_t size, void *base, const char *file, int line, bool array)
{
acquire_lock();
// if we're out of free entries, allocate a new chunk
if (s_freehead == nullptr)
{
// create a new chunk, and fail if we can't
memory_entry *entry = reinterpret_cast<memory_entry *>(osd_malloc_array(memory_block_alloc_chunk * sizeof(memory_entry)));
if (entry == nullptr)
{
release_lock();
return nullptr;
}
// add all the entries to the list
for (int entrynum = 0; entrynum < memory_block_alloc_chunk; entrynum++)
{
entry->m_next = s_freehead;
s_freehead = entry++;
}
}
// grab a free entry
memory_entry *entry = s_freehead;
s_freehead = entry->m_next;
// populate it
entry->m_size = size;
entry->m_base = base;
entry->m_file = s_tracking ? file : nullptr;
entry->m_line = s_tracking ? line : 0;
entry->m_id = s_curid++;
entry->m_array = array;
if (LOG_ALLOCS)
fprintf(stderr, "#%06d, alloc %d bytes (%s:%d)\n", (UINT32)entry->m_id, static_cast<UINT32>(entry->m_size), entry->m_file, (int)entry->m_line);
// add it to the alloc list
int hashval = reinterpret_cast<FPTR>(base) % k_hash_prime;
entry->m_next = s_hash[hashval];
if (entry->m_next != nullptr)
entry->m_next->m_prev = entry;
entry->m_prev = nullptr;
s_hash[hashval] = entry;
release_lock();
return entry;
}
示例13: osd_malloc_array
void *malloc_array_file_line(size_t size, const char *file, int line)
{
// allocate the memory and fail if we can't
void *result = osd_malloc_array(size);
if (result == NULL)
return NULL;
// add a new entry
memory_entry::allocate(size, result, file, line);
#if !__has_feature(memory_sanitizer) && defined(MAME_DEBUG)
memset(result, 0xdd, size);
#endif
return result;
}
示例14: osd_malloc_array
void *malloc_array_file_line(size_t size, const char *file, int line)
{
// allocate the memory and fail if we can't
void *result = osd_malloc_array(size);
if (result == NULL)
return NULL;
// add a new entry
memory_entry::allocate(size, result, file, line);
#ifdef MAME_DEBUG
// randomize the memory
rand_memory(result, size);
#endif
return result;
}
示例15: osd_setenv
int osd_setenv(const char *name, const char *value, int overwrite)
{
char *buf;
int result;
if (!overwrite)
{
if (osd_getenv(name) != NULL)
return 0;
}
buf = (char *) osd_malloc_array(strlen(name)+strlen(value)+2);
sprintf(buf, "%s=%s", name, value);
result = putenv(buf);
/* will be referenced by environment
* Therefore it is not freed here
*/
return result;
}