Git Product home page Git Product logo

Comments (10)

ardan-bkennedy avatar ardan-bkennedy commented on September 26, 2024 1

Ok. I'll look at this again. It seems I did make the wrong conclusion. After review I'll fix anything that needs to be fixed.

Thanks!!

from gotraining.

ardan-bkennedy avatar ardan-bkennedy commented on September 26, 2024 1

OMG! How did I miss that when I was reviewing this post :(

THANK YOU for finding this and creating an issue. Can you please send me an email. [email protected]. I would like to give you access to the Go Bundle.

I should have a fix in the next hour.

from gotraining.

ardan-bkennedy avatar ardan-bkennedy commented on September 26, 2024

Your code example is not using the slices API at all?

Your 3 index slice examples are a smell. I have never found a reason for the last two values not to be the same.

from gotraining.

pavelosipyants-sothebys2 avatar pavelosipyants-sothebys2 commented on September 26, 2024

Sorry, I may be wasn't clear enough.
Here is the code with slices API, basically expressing the same idea.

package main

import (
	"fmt"
	"slices"
)

func main() {
	var arr [10000]int
	fmt.Println("arr", &arr[0])
	fmt.Printf("Len(%d), Cap(%d)\n", len(arr), cap(arr))

	slArr := arr[:10]
	fmt.Println("slArr", &slArr[0])
	fmt.Printf("Len(%d), Cap(%d)\n", len(slArr), cap(slArr))

	slArr = slices.Clip(slArr)
	fmt.Println("slArr", &slArr[0])
	fmt.Printf("Len(%d), Cap(%d)\n", len(slArr), cap(slArr))
}

This code shows that the underlying array for slArr after slices.Clip doesn't change.
It's still the array taking O(10000) memory.


The Figure 3 of the post shows that after list = slices.Clip(list) new list slice points to the new underlying array with smaller size.

Figure 3 shows the slice value and underlying array after the clip operation.

So in case of the code above it would mean that slArr after slices.Clip points to a new array taking O(10) memory.

May be you meant smth else with Figure 3, but at least that's how I read it. And probably other readers of your post can read it in the same way. For me it looked like slices.Clip makes a new slice with new underlying array of (probably) smaller size and copies elements from the original slice. This probably can lead to a wrong opinion that slices.Clip can be used to save allocated memory of a process and free some memory to be garbage collected.

from gotraining.

pavelosipyants-sothebys2 avatar pavelosipyants-sothebys2 commented on September 26, 2024

I am happy to help :)

from gotraining.

pavelosipyants-sothebys2 avatar pavelosipyants-sothebys2 commented on September 26, 2024

@ardan-bkennedy

I've sent you an email, btw. May be you need to check your spam folder.

from gotraining.

ardan-bkennedy avatar ardan-bkennedy commented on September 26, 2024

I've been out for a few days but I don't see it. Can you send it again please.

from gotraining.

pavelosipyants-sothebys2 avatar pavelosipyants-sothebys2 commented on September 26, 2024

Done ✅

from gotraining.

ardan-bkennedy avatar ardan-bkennedy commented on September 26, 2024

What is your email?

from gotraining.

pavelosipyants-sothebys2 avatar pavelosipyants-sothebys2 commented on September 26, 2024

[email protected]

from gotraining.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.