我正在玩Go,并且还没有一个很好的心理模型,当结构通过值或引用传递时.
这可能是一个非常愚蠢的问题,但我只是想进行一些实验,看看我是否还在处理相同的对象,或者我已经复制了它(通过值传递它).
有没有办法打印对象的指针(或指针值由gc更改的内部id)?
package main
import ( "runtime" )
type Something struct {
number int
queue chan int
}
func gotest( s *Something, done chan bool ) {
println( "from gotest:")
println( &s )
for num := range s.queue {
println( num )
s.number = num
}
done <- true
}
func main() {
runtime.GOMAXPROCS(4)
s := new(Something)
println(&s)
s.queue = make(chan int)
done := make(chan bool)
go gotest(s, done)
s.queue <- 42
close(s.queue)
<- done
println(&s)
println(s.number)
}
Run Code Online (Sandbox Code Playgroud)
在我的窗口上给出(8g编译版本): …
我目前正在根据Python Cookbook的第12.5章运行以下代码:
from xml.parsers import expat
class Element(object):
def __init__(self, name, attributes):
self.name = name
self.attributes = attributes
self.cdata = ''
self.children = []
def addChild(self, element):
self.children.append(element)
def getAttribute(self,key):
return self.attributes.get(key)
def getData(self):
return self.cdata
def getElements(self, name=''):
if name:
return [c for c in self.children if c.name == name]
else:
return list(self.children)
class Xml2Obj(object):
def __init__(self):
self.root = None
self.nodeStack = []
def StartElement(self, name, attributes):
element = Element(name.encode(), attributes)
if self.nodeStack:
parent = self.nodeStack[-1]
parent.addChild(element)
else:
self.root …Run Code Online (Sandbox Code Playgroud) 我在一堆子目录中有源代码,如:
src/widgets/apple.cpp
src/widgets/knob.cpp
src/tests/blend.cpp
src/ui/flash.cpp
Run Code Online (Sandbox Code Playgroud)
在项目的根目录中,我想使用以下规则生成单个Makefile:
%.o: %.cpp
$(CC) -c $<
build/test.exe: build/widgets/apple.o build/widgets/knob.o build/tests/blend.o src/ui/flash.o
$(LD) build/widgets/apple.o .... build/ui/flash.o -o build/test.exe
Run Code Online (Sandbox Code Playgroud)
当我尝试这个时,它找不到build/widgets/apple.o的规则.我是否可以更改某些内容,以便在需要生成build/widgets/apple.o时使用%.o:%.cpp?
我有一个非常大(只读)的数据数组,我希望由多个进程并行处理.
我喜欢Pool.map函数,并希望用它来并行计算该数据的函数.
我看到可以使用Value或Array类在进程之间使用共享内存数据.但是当我尝试使用它时,我得到一个RuntimeError:'SynchronizedString对象只应在使用Pool.map函数时通过继承在进程之间共享:
这是我想要做的简化示例:
from sys import stdin
from multiprocessing import Pool, Array
def count_it( arr, key ):
count = 0
for c in arr:
if c == key:
count += 1
return count
if __name__ == '__main__':
testData = "abcabcs bsdfsdf gdfg dffdgdfg sdfsdfsd sdfdsfsdf"
# want to share it using shared memory
toShare = Array('c', testData)
# this works
print count_it( toShare, "a" )
pool = Pool()
# RuntimeError here
print pool.map( count_it, [(toShare,key) for key in ["a", …Run Code Online (Sandbox Code Playgroud) 这是我的情况:我对Perl几乎一无所知,但它是移植机器上唯一可用的语言.我只有权在我的本地工作区写入,而不是Perl安装位置.我需要使用CPAN 的Parallel :: ForkManager Perl模块
如何在不进行集中安装的情况下使用此Parallel :: ForkManager?是否有我可以设置的环境变量,因此它位于?
谢谢
JD
说我有一个矢量:
(def data ["Hello" "World" "Test" "This"])
Run Code Online (Sandbox Code Playgroud)
我想在一个有api的地方填充一张桌子:
(defn setCell
[row col value]
(some code here))
Run Code Online (Sandbox Code Playgroud)
那么获得以下调用的最佳方法是什么:
(setCell 0 0 "Hello")
(setCell 0 1 "World")
(setCell 0 2 "Test")
(setCell 0 3 "This")
Run Code Online (Sandbox Code Playgroud)
我发现以下内容可行:
(let [idv (map vector (iterate inc 0) data)]
(doseq [[index value] idv] (setCell 0 index value)))
Run Code Online (Sandbox Code Playgroud)
但是有没有更快的方法不需要新的临时数据结构idv?
几年前,我参与了一个绿色的田野项目,在那里我们进行了极限编程.我也看到很多人提到Scrum方法.
有人能告诉我Scrum和XP之间的主要区别吗?
我想知道STL是否有这方面的支持:
说我有这样一个类:
class Person
{
public:
int getAge() const;
double getIncome() const;
..
..
};
Run Code Online (Sandbox Code Playgroud)
和矢量:
vector<Person*> people;
Run Code Online (Sandbox Code Playgroud)
我想按照他们的年龄对人的矢量进行排序:我知道我可以通过以下方式进行:
class AgeCmp
{
public:
bool operator() ( const Person* p1, const Person* p2 ) const
{
return p1->getAge() < p2->getAge();
}
};
sort( people.begin(), people.end(), AgeCmp() );
Run Code Online (Sandbox Code Playgroud)
是否有一个不那么冗长的方法来做到这一点?仅仅因为我想基于'属性'进行排序而必须定义整个类似乎有点过分.这样的事可能吗?
sort( people.begin(), people.end(), cmpfn<Person,Person::getAge>() );
Run Code Online (Sandbox Code Playgroud) 您将如何在以下代码中实现deleteRecords函数:
Example:
type Record struct {
id int
name string
}
type RecordList []*Record
func deleteRecords( l *RecordList, ids []int ) {
// Assume the RecordList can contain several 100 entries.
// and the number of the of the records to be removed is about 10.
// What is the fastest and cleanest ways to remove the records that match
// the id specified in the records list.
}
Run Code Online (Sandbox Code Playgroud) 我今天一直在玩D 2.0,主要是因为DDJ中的"D案例".
我已经为Windows下载了D 2.0,但还没有想出如何在调试器中单步执行正在运行的程序.
我试图让windbg.exe的发货副本工作,但它一直在崩溃,似乎没有看到源代码.
go ×2
python ×2
agile ×1
attributes ×1
c++ ×1
clojure ×1
cpan ×1
d ×1
debugging ×1
installation ×1
loops ×1
makefile ×1
methodology ×1
module ×1
parsing ×1
performance ×1
perl ×1
permissions ×1
pool ×1
scrum ×1
slice ×1
sorting ×1
stl ×1
vector ×1
xml ×1