Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Allocating memory for function pointers [modified]

Allocating memory for function pointers [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialsecurityperformancehelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SelvaKr
    wrote on last edited by
    #1

    Hi, I am working in a porting project where i have to convert the thread local variables (declared with __declspec(thread)) to TLS allocations (using TLS APIs). I am able to do it for variables. How to do it for function pointers? (thread local function pointers) for example, I have a thread local function pointer declared as, __declspec(thread) BOOL (WINAPI *Test)(Short a, _TCHAR b, BOOL c); Is it possible to convert this by using TLS APIs? Is it possible to allocate the memory (4 bytes) for pointer "Test"? Any help is appreciated. Thanks.

    Selva

    A 1 Reply Last reply
    0
    • S SelvaKr

      Hi, I am working in a porting project where i have to convert the thread local variables (declared with __declspec(thread)) to TLS allocations (using TLS APIs). I am able to do it for variables. How to do it for function pointers? (thread local function pointers) for example, I have a thread local function pointer declared as, __declspec(thread) BOOL (WINAPI *Test)(Short a, _TCHAR b, BOOL c); Is it possible to convert this by using TLS APIs? Is it possible to allocate the memory (4 bytes) for pointer "Test"? Any help is appreciated. Thanks.

      Selva

      A Offline
      A Offline
      Aescleal
      wrote on last edited by
      #2

      Test is just a variable with type:

      BOOL (WINAPI *)(Short, _TCHAR, BOOL );

      so all you need to do is cast the result of you TLS allocation to that type. If you use a quick typedef it's pretty trivial:

      typedef BOOL (WINAPI *test_function_ptr)( Short, _TCHAR, BOOL );

      test_function_ptr Test = (test_function_ptr)malloc( sizeof( test_function_ptr ) );

      Replace malloc with what ever TLS function you're using and snip, snip, Bob's your Aunty. Cheers, Ash

      S 1 Reply Last reply
      0
      • A Aescleal

        Test is just a variable with type:

        BOOL (WINAPI *)(Short, _TCHAR, BOOL );

        so all you need to do is cast the result of you TLS allocation to that type. If you use a quick typedef it's pretty trivial:

        typedef BOOL (WINAPI *test_function_ptr)( Short, _TCHAR, BOOL );

        test_function_ptr Test = (test_function_ptr)malloc( sizeof( test_function_ptr ) );

        Replace malloc with what ever TLS function you're using and snip, snip, Bob's your Aunty. Cheers, Ash

        S Offline
        S Offline
        SelvaKr
        wrote on last edited by
        #3

        Hi Ash, Thanks. It works.

        Selva

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups