Page 88 - DCAP408_WEB_PROGRAMMING
P. 88

Windows Programming




                    Notes          Local memory is however managed such that consecutive 32-bit words are used by consecutive
                                   thread IDs. Accesses are as a result fully coalesced as long as all threads in a warp access the
                                   similar relative address (e.g. similar index in an array variable, similar member in a structure
                                   variable). On devices of compute capability 2.0, local memory accesses are at all times cached in
                                   L1 and L2 in the similar manner as global memory accesses
                                   Self Assessment


                                   Fill in the blanks:
                                   1.  .................... memory exists in device memory  and device memory is used through 32,
                                       64–, or 128-byte memory transactions.
                                   2.  For structures, the size and alignment necessities can be enforced by the compiler using
                                       the alignment .....................

                                   3.  .................... memory accesses only happen for some automatic variables.
                                   5.2 Local Memory Blocks


                                   Under Win16, there are two major groups of memory API functions: Global and Local. Global-
                                   type API calls deal with memory assigned in other segments therefore they’re “far” memory
                                   functions. Local-type API calls deal with the local heap of the process so they’re “near” memory
                                   functions. Under Win32, these two types are indistinguishable. Whether you call GlobalAlloc or
                                   LocalAlloc, you get the similar result.
                                   Steps in assigning and using memory are as below:
                                   1.  Assign a block of memory by calling LocalAlloc. This function returns a handle to the
                                       requested memory  block.
                                   2.  “Lock” the memory block by calling LocalLock. This function accepts a handle to the
                                       memory block and returns a pointer to the memory block.
                                   3.  You can utilize the pointer to read or write memory.
                                   4.  “Unlock” the memory block by calling LocalUnlock . This function cancels the pointer to
                                       the memory block.
                                   5.  Free the memory block by calling LocalFree. This function  accepts the  handle to  the
                                       memory block.

                                   You can also replace “Local” by “Global” like GloballAlloc, GlobalLock, etc.
                                   The  above  method  can  be  further  simplified  by  means  of  a  flag  in  GlobalAlloc  call,
                                   GMEM_FIXED. If you use this flag, the return value from Global/LocalAlloc will be the pointer
                                   to the assigned memory block, not the memory block handle. You don’t have to call Global/
                                   LocalLock and you can pass the pointer to Global/LocalFree without calling Global/LocalUnlock
                                   first.

                                   Self Assessment

                                   Fill in the blanks:
                                   4.  Local-type API calls deal with the local .................... of the process so they’re “near” memory
                                       functions.
                                   5.  .................... function returns a handle to the requested memory block.




          82                                LOVELY PROFESSIONAL UNIVERSITY
   83   84   85   86   87   88   89   90   91   92   93