C++ (Cpp) sizeof Examples

C++ (Cpp) sizeof - 30 examples found. These are the top rated real world C++ (Cpp) examples of sizeof extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
static int __init _mhal_alsa_init(void)
{
    int err = 0;

    MAD_PRINT(KERN_INFO "Initiate MStar ALSA core driver\n");

    memset(&MStar_MAD, 0x00, sizeof(struct MStar_MAD_Info));

    memcpy(MStar_MAD.name, _MAD_CHIP_MODEL, sizeof(MStar_MAD.name));
    sprintf(MStar_MAD.version, "%d.%d.%d", _MAD_ALSA_HAL_VERSION_MAJOR, _MAD_ALSA_HAL_VERSION_MINOR, _MAD_ALSA_HAL_VERSION_REVISION);

    /* Hook Playback Operators */
    MStar_MAD.playback_pcm_ops[0] = &MStar_DMA_Reader_Ops;

    /* Hook Capture Operators */
    MStar_MAD.capture_pcm_ops[0] = &MStar_PCM_Capture1_Ops;
    MStar_MAD.capture_pcm_ops[1] = &MStar_PCM_Capture2_Ops;

    err = _mdrv_alsa_hook_device(&MStar_MAD);
    if (err < 0) {
        MAD_PRINT(KERN_ERR "Error(%d)! fail to hook PCM operators\n", err);
        return err;
    }

    return 0;
}
/**

  Pool allocation service. Before permenent memory is discoveried, the pool will
  be allocated the heap in the temporary memory. Genenrally, the size of heap in temporary
  memory does not exceed to 64K, so the biggest pool size could be allocated is
  64K.

  @param PeiServices               An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
  @param Size                      Amount of memory required
  @param Buffer                    Address of pointer to the buffer

  @retval EFI_SUCCESS              The allocation was successful
  @retval EFI_OUT_OF_RESOURCES     There is not enough heap to satisfy the requirement
                                   to allocate the requested size.

**/
EFI_STATUS
EFIAPI
PeiAllocatePool (
    IN CONST EFI_PEI_SERVICES     **PeiServices,
    IN       UINTN                Size,
    OUT      VOID                 **Buffer
)
{
    EFI_STATUS               Status;
    EFI_HOB_MEMORY_POOL      *Hob;

    //
    // If some "post-memory" PEIM wishes to allocate larger pool,
    // it should use AllocatePages service instead.
    //

    //
    // Generally, the size of heap in temporary memory does not exceed to 64K,
    // HobLength is multiples of 8 bytes, so the maxmium size of pool is 0xFFF8 - sizeof (EFI_HOB_MEMORY_POOL)
    //
    if (Size > (0xFFF8 - sizeof (EFI_HOB_MEMORY_POOL))) {
        return EFI_OUT_OF_RESOURCES;
    }

    Status = PeiServicesCreateHob (
                 EFI_HOB_TYPE_MEMORY_POOL,
                 (UINT16)(sizeof (EFI_HOB_MEMORY_POOL) + Size),
                 (VOID **)&Hob
             );
    ASSERT_EFI_ERROR (Status);
    *Buffer = Hob+1;

    return Status;
}
Example #3
0
void Compression::CompressStreamToFile(const BYTE *stream, UINT byteCount, const String &filename)
{
    BYTE *compressedStream = new BYTE[byteCount + 64];

    z_stream zstream;

    zstream.zalloc = Z_NULL;
    zstream.zfree = Z_NULL;
    zstream.opaque = Z_NULL;

    zstream.avail_in = byteCount;
    zstream.next_in = const_cast<BYTE*>(stream);

    zstream.data_type = Z_BINARY;

    zstream.avail_out = byteCount + 64;
    zstream.next_out = compressedStream;

    const int Level = 6;
    //Result = deflateInit(&Stream, Level);
    int result = deflateInit2(&zstream, Level, Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
    PersistentAssert(result == Z_OK, "deflateInit failed");

    result = deflate(&zstream, Z_FINISH);
    PersistentAssert(result == Z_STREAM_END, "deflate failed");

    deflateEnd(&zstream);

    FILE *file = Utility::CheckedFOpen(filename.CString(), "wb");
    Utility::CheckedFWrite(&byteCount, sizeof(UINT32), 1, file);
    Utility::CheckedFWrite(compressedStream, sizeof(BYTE), zstream.total_out, file);
    fclose(file);

    delete[] compressedStream;
}
/* ****************************************************************************
*
* jsonRender -
*/
TEST(UnsubscribeContextResponse, jsonRender)
{
    const char*                  infile1  = "ngsi10.unsubscribeContextResponse.jsonRender1.valid.json";
    const char*                  infile2  = "ngsi10.unsubscribeContextResponse.jsonRender2.valid.json";
    UnsubscribeContextResponse*  uncrP;
    std::string                  out;

    utInit();

    // Preparations
    uncrP = new UnsubscribeContextResponse();

    // 1. 400, with details
    uncrP->subscriptionId.set("012345678901234567890123");
    uncrP->statusCode.fill(SccBadRequest, "details");

    EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), infile1)) << "Error getting test data from '" << infile1 << "'";
    out = uncrP->render(QueryContext, JSON, "");
    EXPECT_STREQ(expectedBuf, out.c_str());


    // 2. 200, no details
    uncrP->subscriptionId.set("012345678901234567890123");
    uncrP->statusCode.fill(SccOk);

    EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), infile2)) << "Error getting test data from '" << infile2 << "'";
    out = uncrP->render(QueryContext, JSON, "");
    EXPECT_STREQ(expectedBuf, out.c_str());

    delete uncrP;

    utExit();
}
Example #5
0
void *osd_malloc_array(size_t size)
{
#ifndef MALLOC_DEBUG
    return malloc(size);
#else
    // add in space for the size and offset
    size += MAX_ALIGNMENT + sizeof(size_t) + 2;
    size &= ~size_t(1);

    // round the size up to a page boundary
    size_t const rounded_size = ((size + sizeof(void *) + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE;

    // reserve that much memory, plus two guard pages
    void *page_base = VirtualAlloc(nullptr, rounded_size + 2 * PAGE_SIZE, MEM_RESERVE, PAGE_NOACCESS);
    if (page_base == nullptr)
        return nullptr;

    // now allow access to everything but the first and last pages
    page_base = VirtualAlloc(reinterpret_cast<UINT8 *>(page_base) + PAGE_SIZE, rounded_size, MEM_COMMIT, PAGE_READWRITE);
    if (page_base == nullptr)
        return nullptr;

    // work backwards from the page base to get to the block base
    UINT8 *const block = GUARD_ALIGN_START ? reinterpret_cast<UINT8 *>(page_base) : (reinterpret_cast<UINT8 *>(page_base) + rounded_size - size);
    UINT8 *const result = reinterpret_cast<UINT8 *>(reinterpret_cast<FPTR>(block + sizeof(size_t) + MAX_ALIGNMENT) & ~(FPTR(MAX_ALIGNMENT) - 1));

    // store the size at the start with a flag indicating it has a guard page
    *reinterpret_cast<size_t *>(block) = size | 1;
    *(result - 1) = result - block;
    return result;
#endif
}
Example #6
0
static const char *trapname(int trapno)
{
    static const char * const excnames[] = {
        "Divide error",
        "Debug",
        "Non-Maskable Interrupt",
        "Breakpoint",
        "Overflow",
        "BOUND Range Exceeded",
        "Invalid Opcode",
        "Device Not Available",
        "Double Fault",
        "Coprocessor Segment Overrun",
        "Invalid TSS",
        "Segment Not Present",
        "Stack Fault",
        "General Protection",
        "Page Fault",
        "(unknown trap)",
        "x87 FPU Floating-Point Error",
        "Alignment Check",
        "Machine-Check",
        "SIMD Floating-Point Exception"
    };

    if (trapno < sizeof(excnames)/sizeof(excnames[0]))
        return excnames[trapno];
    if (trapno == T_SYSCALL)
        return "System call";
    return "(unknown trap)";
}