dcsimg
Results 1 to 5 of 5
  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2016
    Posts
    12

    StrPtr and memory question

    I have a questiona bout StrPtr function. It's my understanding it's dealing with memory. Do I need to de-reference it somehow after it's being called to release memory so that it does not cause any memory leak or cache?

    Thanks

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,275

    Re: StrPtr and memory question

    StrPtr is a pointer to a memory allocation. If you are copying memory from that pointer, then the memory you copied needs to be addressed, but not the pointer. Does that help?

    StrPtr is to strings what ObjPtr is to objects.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,298

    Re: StrPtr and memory question

    Here's a nice little image I took from here:

    Name:  strptr.jpg
Views: 57
Size:  21.7 KB

    And Microsoft also has a nice page that explains BSTRs, seen here.

    It's a matter of pointers (StrPtr) versus pointers-to-pointers (VarPtr).

    And StrPtr just returns a Long, so there's really nothing to release. Whatever Long you assign the return to will be released by VB6 when it goes out of scope.

    Good Luck,
    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  4. #4
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,241

    Re: StrPtr and memory question

    And don't forget, that there is only one thing, you can do in VB with a pointer:

    Pass it along to a Win-API

    And no, i'm not talking about pointer-arithmetic.
    You can get a Pointer to somewhere (a long-variable, a string, my dirty socks under my bed), but changing that pointer within VB (e.g. add a value to move it forward),
    and then pass it along to a Win-API, you do all on your own risk.
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    I say you're crazy not to!
    --------------------------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,275

    Re: StrPtr and memory question

    Quote Originally Posted by Zvoni View Post
    And don't forget, that there is only one thing, you can do in VB with a pointer:

    Pass it along to a Win-API
    For the most part, agreed. But in VB, another use is to distinguish "" from vbNullString
    Code:
    "" = vbNullString  ' true
    StrPtr("") = StrPtr(vbNullString) ' false
    StrPtr is preferred way to determine if someone hit the 'Cancel' button in an InputBox.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.