C++ (Cpp) calloc Examples

C++ (Cpp) calloc - 30 examples found. These are the top rated real world C++ (Cpp) examples of calloc extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
PerformanceMonitor::PerformanceMonitor(void)
{
    this->dispMemory = 0;
    this->unitIndex = 0;
    this->totalDispMemory = 0;
    this->totalUnitIndex = 0;
    this->ppi = NULL;

    SYSTEM_INFO si = {0};
    GetSystemInfo(&si);
    this->cpuCount = si.dwNumberOfProcessors;
    this->phCounters = (HCOUNTER*)calloc(this->cpuCount + 1, sizeof(HCOUNTER));
    this->prevPercentages = (char*) calloc(this->cpuCount + 1, sizeof(char));
    this->currPercentages = (char*) calloc(this->cpuCount + 1, sizeof(char));

    this->bPdhSuccess = PdhOpenQuery(NULL, 0, &this->hQuery) == ERROR_SUCCESS;
    PdhAddCounter(hQuery, _T("\\Processor(_Total)\\% Processor Time"), 0, phCounters);
    TCHAR* format = _T("\\Processor(%d)\\%% Processor Time");
    for (int i = 0; i < this->cpuCount; i++) {
        TCHAR name[32] = {0};
        _stprintf_p(name, sizeof(name), format, i);
        PdhAddCounter(hQuery, name, 0, phCounters + i + 1);
    }
    PdhCollectQueryData(hQuery);

    this->totalDispMemory = this->getDispMemory(this->getTotalMemoryBytes(), &this->totalUnitIndex);
}
Example #2
0
/* Initialize the paths to config file, lock files and store root.
 */
static int semanage_init_paths(const char *root) {
    size_t len, prefix_len;
    int i;

    if (!root)
        return -1;

    prefix_len = (strlen(root) + strlen(SEMANAGE_MOD_DIR));

    for (i = 0; i < SEMANAGE_NUM_FILES; i++) {
        len = (strlen(semanage_relative_files[i]) + prefix_len);
        semanage_files[i] = calloc(len + 1, sizeof(char));
        if (!semanage_files[i])
            return -1;
        sprintf(semanage_files[i], "%s%s%s", root, SEMANAGE_MOD_DIR,
                semanage_relative_files[i]);
    }

    len = strlen(selinux_path()) + strlen(SEMANAGE_CONF_FILE);
    semanage_conf = calloc(len + 1, sizeof(char));
    if (!semanage_conf)
        return -1;
    snprintf(semanage_conf, len, "%s%s", selinux_path(), SEMANAGE_CONF_FILE);

    return 0;
}
Example #3
0
/* This initializes the paths inside the stores, this is only necessary
 * when directly accessing the store
 */
static int semanage_init_store_paths(const char *root) {
    int i, j;
    size_t len;
    size_t prefix_len;
    char *prefix;

    if (!root)
        return -1;

    prefix_len = (strlen(root) + strlen(SEMANAGE_MOD_DIR));
    prefix = calloc(prefix_len + 1, sizeof(char));
    if (!prefix)
        return -1;
    sprintf(prefix, "%s%s", root, SEMANAGE_MOD_DIR);

    for (i = 0; i < SEMANAGE_NUM_STORES; i++) {
        for (j = 0; j < SEMANAGE_STORE_NUM_PATHS; j++) {
            len = prefix_len + strlen(semanage_store_paths[i])
                  + strlen(semanage_sandbox_paths[j]);
            semanage_paths[i][j] = calloc(len + 1, sizeof(char));
            if (!semanage_paths[i][j])
                goto cleanup;
            sprintf(semanage_paths[i][j], "%s%s%s", prefix,
                    semanage_store_paths[i],
                    semanage_sandbox_paths[j]);
        }
    }

cleanup:
    free(prefix);
    return 0;
}
Example #4
0
File: log.c Project: RAttab/ilka
static struct log_ring *ring_get()
{
    pthread_once(&ring_once, &ring_init);

    struct log_ring *ring = pthread_getspecific(ring_key);
    if (ring) return ring;

    ring = calloc(1, sizeof(struct log_ring));
    ring->data = calloc(ring_size, sizeof(struct log_msg));

    if (pthread_setspecific(ring_key, ring)) {
        ilka_fail_errno("unable to set log thread specific data");
        ilka_abort();
    }

    {
        slock_lock(&ring_lock);

        ring->next = ring_head;
        ring_head = ring;

        slock_unlock(&ring_lock);
    }

    return ring;
}
static void
gl_compile_link_error(GLuint target, const char *action)
{
    int loglen = 0, chars = 0;
    char *logtxt;

    /* Shader info log */
    glGetShaderiv(target, GL_INFO_LOG_LENGTH, &loglen);
    if (loglen > 0)
    {
        logtxt = calloc(loglen, sizeof(char));
        if (logtxt)
        {
            glGetShaderInfoLog(target, loglen, &chars, logtxt);
            ERR("Failed to %s: %s", action, logtxt);
            free(logtxt);
        }
    }

    /* Program info log */
    glGetProgramiv(target, GL_INFO_LOG_LENGTH, &loglen);
    if (loglen > 0)
    {
        logtxt = calloc(loglen, sizeof(char));
        if (logtxt)
        {
            glGetProgramInfoLog(target, loglen, &chars, logtxt);
            ERR("Failed to %s: %s", action, logtxt);
            free(logtxt);
        }
    }
}
Example #6
0
/*!
 * \brief Read a ESRI grid data file (.flt)
 * \param myFileName string name file
 * \param myGrid Crit3DRasterGrid pointer
 * \param myError string pointer
 * \return true on success, false otherwise
 */
bool readEsriGridFlt(string myFileName, gis::Crit3DRasterGrid *myGrid, string *myError)
{
    myFileName += ".flt";

    FILE* filePointer;

    /*! alloc memory */
    myGrid->value = (float **) calloc(myGrid->header->nrRows, sizeof(float *));
    for (long myRow = 0; myRow < myGrid->header->nrRows; myRow++)
    {
        myGrid->value[myRow] = (float *) calloc(myGrid->header->nrCols, sizeof(float));
        if (myGrid->value[myRow] == NULL)
        {
            *myError = "Memory error: file too big.";
            myGrid->freeGrid();
            return(false);
        }
    }

    filePointer = fopen (myFileName.c_str(), "rb" );
    if (filePointer == NULL)
    {
        *myError = "File .flt error.";
        return(false);
    }

    for (long myRow = 0; myRow < myGrid->header->nrRows; myRow++)
        fread (myGrid->value[myRow], sizeof(float), myGrid->header->nrCols, filePointer);

    fclose (filePointer);

    return (true);
}