我想要做的是改变C#方法在调用时的执行方式,这样我就可以编写如下内容:
[Distributed]
public DTask<bool> Solve(int n, DEvent<bool> callback)
{
for (int m = 2; m < n - 1; m += 1)
if (m % n == 0)
return false;
return true;
}
Run Code Online (Sandbox Code Playgroud)
在运行时,我需要能够分析具有Distributed属性(我已经可以做)的方法,然后在函数体执行之前和函数返回之后插入代码.更重要的是,我需要能够在不修改调用Solve的代码的情况下或在函数的开头修改代码(在编译时;在运行时这样做是目标).
目前我尝试了这段代码(假设t是Solve存储的类型,m是Solve的MethodInfo):
private void WrapMethod(Type t, MethodInfo m)
{
// Generate ILasm for delegate.
byte[] il = typeof(Dpm).GetMethod("ReplacedSolve").GetMethodBody().GetILAsByteArray();
// Pin the bytes in the garbage collection.
GCHandle h = GCHandle.Alloc((object)il, GCHandleType.Pinned);
IntPtr addr = h.AddrOfPinnedObject();
int size = il.Length;
// Swap the method.
MethodRental.SwapMethodBody(t, m.MetadataToken, …Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的Kubernetes部署(用'....'替换名称和其他东西):
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "3"
kubernetes.io/change-cause: kubectl replace deployment ....
-f - --record
creationTimestamp: 2016-08-20T03:46:28Z
generation: 8
labels:
app: ....
name: ....
namespace: default
resourceVersion: "369219"
selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/....
uid: aceb2a9e-6688-11e6-b5fc-42010af000c1
spec:
replicas: 2
selector:
matchLabels:
app: …Run Code Online (Sandbox Code Playgroud) 我有一个C#项目,其中包含对ScintillaNET的引用.不幸的是,ScintillaNET喜欢检测机器的架构并根据运行的架构加载本机DLL.这意味着我的项目必须预编译为x86和x64版本(由于上述检测,我无法使用任何CPU).
问题是我的构建服务器只是x86.有没有办法在x86机器上以x64模式编译.NET程序集?据我所知,切换只是强制计算机加载所需架构的程序集,并且实际上并不在编译时输出任何与架构相关的代码,但是,在构建服务器上的Mono 2.10.6下进行编译时得到如下错误:
"错误CS0016:无法写入文件`ScintillaNet',原因:AMD64"
我不能使用CorFlags.exe来更改PE头,因为这是一个基于Linux的构建服务器.有没有办法做到这一点?
我正在尝试将委托类型作为类型参数传递,以便我可以稍后在代码中将其用作类型参数,如下所示:
// Definition
private static class Register
{
public static FunctionObject Create<T>(CSharp.Context c, T func)
{
return new IronJS.HostFunction<T>(c.Environment, func, null);
}
}
// Usage
Register.Create<Func<string, IronJS.CommonObject>>(c, this.Require);
Run Code Online (Sandbox Code Playgroud)
但是,C#编译器抱怨:
The type 'T' cannot be used as type parameter 'a' in the generic type or method
'IronJS.HostFunction<a>'. There is no boxing conversion or type parameter
conversion from 'T' to 'System.Delegate'."
Run Code Online (Sandbox Code Playgroud)
我试图通过在函数中附加"where T:System.Delegate"来解决这个问题,但是,你不能使用System.Delegate作为类型参数的限制:
Constraint cannot be special class 'System.Delegate'
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这个冲突?
不工作(在演员表中参数和返回类型信息丢失):
Delegate d = (Delegate)(object)(T)func;
return new IronJS.HostFunction<Delegate>(c.Environment, d, null);
Run Code Online (Sandbox Code Playgroud) 我有一个像这样定义的类:
class Client():
def __new__(cls):
print "NEW"
return cls
def __init__(self):
print "INIT"
Run Code Online (Sandbox Code Playgroud)
当我使用它时,我得到以下输出:
cl = Client()
# INIT
Run Code Online (Sandbox Code Playgroud)
__new__没有被召唤.为什么?
在下面的代码中,似乎client.Connect.Receive永久地固定"byte []结果",导致永远不会释放内存(因为它总是被固定).我正在寻找一种方法来告诉C#,在使用它之后不再需要固定它.OnReceive,但我找不到内置函数或关键字来执行此操作.
有谁知道如何让C#取消固定byte []数组?(这是我的C#应用程序中的内存泄漏源之一)
this.m_TcpListener = new TcpListener(this.p_TcpEndPoint.Port);
this.m_TcpThread = new Thread(delegate()
{
try
{
this.m_TcpListener.Start();
while (this.p_Running)
{
TcpClient client = this.m_TcpListener.AcceptTcpClient();
new Thread(() =>
{
try
{
// Read the length header.
byte[] lenbytes = new byte[4];
int lbytesread = client.Client.Receive(lenbytes, 0, 4, SocketFlags.None);
if (lbytesread != 4) return; // drop this packet :(
int length = System.BitConverter.ToInt32(lenbytes, 0);
int r = 0;
// Read the actual data.
byte[] result = new byte[length];
while (r < length)
{ …Run Code Online (Sandbox Code Playgroud) 我有以下Makefile,我想创建"调试"和"最佳"目标,这些目标会影响CPPFLAGS和CFLAGS中的值,如下所示:
include Makefile.inc
DIRS = applib
EXE_APPFS = appfs
EXE_APPMOUNT = appmount
EXE_APPINSPECT = appinspect
EXE_APPCREATE = appcreate
BUILD_APPFS =
BUILD_APPMOUNT = -DAPPMOUNT
OBJS_APPFS = main.o appfs.o
OBJS_APPMOUNT = main.o appmount.o
OBJS_APPINSPECT = appinspect.o
OBJS_APPCREATE = appcreate.o
OBJLIBS = libapp.a
LIBS = -L. -lpthread -lstdc++ -ldl -lrt -largtable2 -lm ./libapp.a /usr/lib64/libfuse.a
# Optimization settings.
debug: CPPFLAGS=$(CPPFLAGS_DEBUG)
debug: CFLAGS=$(CFLAGS_DEBUG)
debug:
@true
optimal: CPPFLAGS=$(CPPFLAGS_OPTIMAL)
optimal: CFLAGS=$(CFLAGS_OPTIMAL)
optimal:
@true
appfs: appfs.o $(OBJLIBS)
@echo "stuff is done here"
appmount: appmount.o $(OBJLIBS)
@echo "stuff is …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个函数,为每个"联系人"启动一个线程,然后(通过网络)查询该联系人的结果.我希望我的等待函数等待最多1.5秒的响应,然后,只需终止任何剩余的线程.
我遇到的问题是函数在所有线程完成之前返回,即使根据逻辑,这也不可能.main函数中的while循环应该等待所有线程完全完成,但我得到以下输出:
FAIL: Storage test 1 exists 0 times in the DHT.
: Storage test 2 exists 0 times in the DHT.
Added storage test 1 to the entries.
Added storage test 2 to the entries.
Run Code Online (Sandbox Code Playgroud)
(FAIL行来自主要测试程序,看看Get()返回了多少结果.)
据我所知,这是不可能的.有谁知道竞争条件可能发生在哪里(或者我做过的任何其他假设都不正确)?
功能定义如下:
public IList<Entry> Get(ID key)
{
ConcurrentBag<Entry> entries = new ConcurrentBag<Entry>();
List<Thread> threads = new List<Thread>();
foreach (Contact c in this.p_Contacts)
{
Thread t = new Thread(delegate()
{
try
{
FetchMessage fm = new FetchMessage(this, c, key);
fm.Send();
int ticks = 0; …Run Code Online (Sandbox Code Playgroud) c# ×5
.net ×2
.net-3.5 ×1
assemblies ×1
cil ×1
delegates ×1
kubernetes ×1
makefile ×1
memory-leaks ×1
methods ×1
mono ×1
pinning ×1
python ×1
python-2.x ×1
swap ×1