CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: size of allocated shared memory

Threaded View

  1. #1
    Join Date
    May 2009

    size of allocated shared memory


    I have two c++ binaries that perform some IPC using shared memory. I didn't write this code and the comments are a little unclear. I need to develop a unambiguous formula for determining the total required amount of shared memory. The data that is passed is the output, basically an array of column headers and a second array of values. It sometimes becomes necessary to change the amount of shared memory if the total amount of output changes significantly over time.

    The SHMEM is allocated as an integer number of pages of size 4096
    #define SHMEMSIZE (4096 * 15)
    // used as third argument in the call to memset
    memset(lpvMem, '\0', SHMEMSIZE);
    The comments say that this is the number of kibibit pages. I thought that a kibibit was 1024 bits, so this comment doesn't make sense to me. Perhaps I am thinking of an older definition from 8-bit operating systems or something like that.

    At any rate, the following are passed through shared memory,
    - an array of characters with sizex elements of 11 characters per element
      a character in 32-bit takes 8-bits, so the size of this array should be
      sizex * (8 * 11)
    - an array of float with sizex elements
      a float in 32-bit takes 32 bits, so the size of this array should be
      sizex * 32
    At 4096 bits per page, I should need
    pages = ( (sizex * (8 * 11)) + (sizex * 32) ) / 4096
    the size of sizex changes from time to time and this is where the shared memory size may also need to be increased.

    At the moment, I am doing integer arithmetic in bash like,
    # example of number of outputs
    # calculate the required number of bits
    total_output = (sizex * (8 * 11)) + (sizex * 32)
    # calculate the number of pages, round up
    num_pages = (( ($total_output + (4095)) / 4096 ))
    # add an extra page
    num_pages=$(($num_pages + 1))
    The bash script is called by make and modifies the appropriate locations in the src code before compilation.

    I realize that this is nowhere near ideal but it works ok in what is a complicated situation with no easy fix.

    My main question is a math check here. Am I calculating this correctly? Am I missing anything? I do build this in 64-bit as well, does that change things? I have not noticed that a value will work in 32-bit but not 64-bit, but I am not very confident about that assessment.

    As always, suggestions are appreciated.

    Last edited by LMHmedchem; October 7th, 2019 at 09:24 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)