Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5989997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:10:51+00:00 2026-05-22T23:10:51+00:00

I am trying to create a map of addresses of objects that I create

  • 0

I am trying to create a map of addresses of objects that I create with the time at which it is allocated. The key is the address returned by the call to new(). How do I get the address returned by new()?

type T struct{a, b int }

func main(){

        var t int64 = time.Nanoseconds()
        memmap := make(map[uint8]int64)
        fmt.Printf("%d\n", t)
        var ptr *T = new(T)
        ptr.a = 1
        ptr.b = 2
        fmt.Printf("%d %d %p %T\n", ptr.a, ptr.b, ptr, ptr)
        //memmap[ptr] = t //gives error
        //var temp uint8 = ptr//gives error
}

Please tell me what should be the type of the key field in the map so that I can store the address returned by new()? I plan to use new() with different types, get the allocated address and map it with the creation time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:10:52+00:00Added an answer on May 22, 2026 at 11:10 pm

    You can use the type Pointer from the unsafe package, but that is, the package name implies it, unsafe. The address itself is a opaque thing and there’s only little use in actually using a address value alone for a map, better use a tuple of type and address. That’s what unsafe.Reflect does provide you. The package reflect offers you the function UnsafeAddr and a lot more.

    I suggest you read the package documentation for reflect and unsafe packages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a map in which the entries time out and get
I'm trying to create a mutable Map with a default that creates a new
I'm trying to create a map, where the key is an int , and
I'm trying to create an xsd schema that will validate a map with an
I am trying to create a wpf control that will display a map image
I'm trying to create a custom javascript class that inherits from google.maps.Map (V3 API).
I'm trying to create a map in Go that is keyed by big integers.
I'm trying to create an image map that acts as an up/down incrementer/decrementer control.
I am trying to create a custom google map using Longitudes and Latitudes that
I am trying to create a map application, something like google maps, that shows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.