你可以这样写:
int i = 3;
int k = 2;
int division = i / k;
int remainder = i % k;
Run Code Online (Sandbox Code Playgroud)
似乎认为这将在低级别上要求ALU执行两个视觉操作:一个返回商,一个返回余数.但是,我相信ALU最有可能在一次操作中计算两者.如果是这种情况,这不是最佳效率.
是否有更有效的方法,而不要求CPU计算两次?换句话说,它可以在C++的单个操作中完成吗?
我正在为Android构建一些硬件测试.我有一个Android.mk文件,它逐个构建这些可执行文件,每个文件使用一块makefile代码,如下所示:
##### shared #####
LOCAL_PATH := $(my-dir)
##### test_number_one #####
test_name := test_number_one
include $(CLEAR_VARS)
LOCAL_CFLAGS := $(commonCflags)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../
LOCAL_MODULE_TAGS := optional eng
LOCAL_SHARED_LIBRARIES := some_library some_other_library
LOCAL_MODULE := $(test_name)
LOCAL_SRC_FILES := tests/$(test_name)/$(test_name).c
include $(BUILD_EXECUTABLE)
##### test_number_two #####
test_name := test_number_two
include $(CLEAR_VARS)
LOCAL_CFLAGS := $(commonCflags)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../
LOCAL_MODULE_TAGS := optional eng
LOCAL_SHARED_LIBRARIES := some_library some_other_library
LOCAL_MODULE := $(test_name)
LOCAL_SRC_FILES := tests/$(test_name)/$(test_name).c
include $(BUILD_EXECUTABLE)
Run Code Online (Sandbox Code Playgroud)
如您所见,每个测试(在include $(CLEAR_VARS)和之间include $(CLEAR_VARS))都会重复大部分代码.我想简化这一点,以便我有一个测试名称列表和一段makefile代码,每个代码都被"调用".我不在乎该代码是否必须拆分成另一个文件.这里有一些python-esque伪代码来演示我的目标:
##### shared #####
LOCAL_PATH := $(my-dir) …Run Code Online (Sandbox Code Playgroud) 那是一口。基本上我有这个:
typedef int (*decker_function_t)(int);
decker_function_t decker;
// Some logic making decker point to a real function
int i = decker(5);
return 1;
Run Code Online (Sandbox Code Playgroud)
但是,我真正想要的是 type 的函数decker_function_t返回 的类型decker_function_t,而不是int. 我无法弄清楚如何使 typedef 自引用。这可能吗?
另请注意,我严格要求的是 C,而不是 C++,
我正在尝试从WPF应用程序的一部分创建JPG.就像截图一样,只有个人UIElement的.我从这里开始:http://www.grumpydev.com/2009/01/03/taking-wpf-screenshots/
我正在使用他的扩展方法,这个方法允许你得到一个byte [] UIElement.GetJpgImage().然后可以使用文件流将其写入JPG图像.如果我制作整个窗口的JPG,它看起来很好!但是,这并不理想,因为它只捕获用户看到的内容.因滚动查看器而无法显示的内容或因为其父级动画为小尺寸而无法显示的内容.
如果我拍摄一个"截图",例如我用于布局的网格: alt text http://img697.imageshack.us/img697/4233/fullscreenshot2.jpg
我得到了这个黑色背景的垃圾.我不希望这样.此外,如果我使用动画折叠了这个网格的高度,我根本不会得到任何东西.这些实际上是模板化的复选框,它们上面应该有黑色文本,网格的背景应该是白色的.以下是其他人编写的代码,用于返回写入文件流的byte []数组:
public static byte[] GetJpgImage(this UIElement source, double scale, int quality)
{
double actualHeight = source.RenderSize.Height;
double actualWidth = source.RenderSize.Width;
double renderHeight = actualHeight * scale;
double renderWidth = actualWidth * scale;
RenderTargetBitmap renderTarget = new RenderTargetBitmap((int) renderWidth, (int) renderHeight, 96, 96, PixelFormats.Pbgra32);
VisualBrush sourceBrush = new VisualBrush(source);
DrawingVisual drawingVisual = new DrawingVisual();
DrawingContext drawingContext = drawingVisual.RenderOpen();
using (drawingContext)
{
drawingContext.PushTransform(new ScaleTransform(scale, scale));
drawingContext.DrawRectangle(sourceBrush, null, …Run Code Online (Sandbox Code Playgroud) 我正在尝试阅读一个非常基本的SVG文件,其中包含以下内容:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="600" height="300" version="1.1" xmlns="http://www.w3.org/2000/svg">
<g stroke="black" >
<line x1="75" y1="160" x2="525" y2="160" stroke-width="10"/>
</g>
</svg>
Run Code Online (Sandbox Code Playgroud)
我正在尝试获取线元素的集合.但是,以下代码不起作用:
XDocument XD = XDocument.Load(PathToFile);
XElement SVG_Element = XD.Root;
var adam = SVG_Element.Elements("line");
Run Code Online (Sandbox Code Playgroud)
在检查变量时,文档正确加载,但变量"adam"保持为null,就好像它找不到具有该名称的任何元素一样.任何帮助表示赞赏.
编辑:使用后代不能解决这个问题.它仍然是空的.
我在Linux主机上运行perl脚本.我正在尝试编写一个分叉的脚本,其中孩子启动一个永远需要的程序,父母在5秒后超时,杀死了孩子.这是我有的:
my $start = time();
my $timeOut = 5;
my $childPid = fork();
if ($childPid) {
# I am the parent, and $childPid is my child
while (kill(0, $childPid)) {
if (time() > $start + $timeOut) {
$numKilled = kill(SIGTERM, $childPid);
printf("numKilled: %s\n", $numKilled);
}
sleep 1;
}
}
else {
# I am the child - do something that blocks forever
`adb -s 410bf6c1 logcat`;
exit;
}
Run Code Online (Sandbox Code Playgroud)
输出:
aschirma@graphics9-lnx:~$ perl perl-fork-test.pl
numKilled: 1
numKilled: 1
numKilled: 1
numKilled: 1 …Run Code Online (Sandbox Code Playgroud) 我有一个包含许多图像的应用程序,它们看起来都一样,并执行类似的任务:
<Image Grid.Column="1" Grid.Row="0" Name="image_prog1_slot0" Stretch="Uniform" Source="bullet-icon.png" StretchDirection="Both" MouseDown="image_prog1_slot0_MouseDown"/>
<Image Grid.Column="1" Grid.Row="1" Name="image_prog1_slot1" Stretch="Uniform" Source="bullet-icon.png" StretchDirection="Both" />
<Image Grid.Column="1" Grid.Row="2" Name="image_prog1_slot2" Stretch="Uniform" Source="bullet-icon.png" StretchDirection="Both" />
Run Code Online (Sandbox Code Playgroud)
现在,我想将每个链接到同一个事件处理程序:
private void image_MouseDown(object sender, MouseButtonEventArgs e)
{
//this_program = ???;
//this_slot = ???;
//slots[this_program][this_slot] = some value;
}
Run Code Online (Sandbox Code Playgroud)
显然,图像的程序编号和插槽编号是其名称的一部分.有没有办法在触发事件处理程序时提取此信息?
我试图使我的应用程序成为主题,这很简单,如下所示:http : //arbel.net/blog/archive/2006/11/03/Forcing-WPF-to-use-a-specific-Windows -theme.aspx
但是,我不知道我现在正在使用什么主题。我正在使用Windows XP默认主题,无论如何。那篇文章说
指定版本和公共密钥令牌很重要
...我从哪里获得这些信息?
我目前有一个看起来像这样的功能:
public void AnimateLayoutTransform(object ControlToAnimate)
{
//Does some stuff
}
Run Code Online (Sandbox Code Playgroud)
我在很多不同的项目中使用这个函数,所以我希望它是非常可重用的.所以现在我将它放在.cs文件中,包含在命名空间和类中:
namespace LayoutTransformAnimation
{
public class LayoutAnims
{
public void AnimateLayoutTransform(object ControlToAnimate)
{
//Do stuff
}
}
}
Run Code Online (Sandbox Code Playgroud)
这个问题是在给定的项目中使用这个函数,我必须做类似的事情
new LayoutTransformAnimation.LayoutAnims().AnimateLayoutTransform(mygrid);
Run Code Online (Sandbox Code Playgroud)
重用单个函数似乎需要做很多工作.有没有办法,至少在没有创建类的新实例的情况下使用该函数?类似于我们如何Double.Parse()创建一个新的double?
我有一个Lisp函数,它返回两个值的MAX,或两个值的MIN.现在我的代码有一些相对复杂的表达式来评估VALUE1和VALUE2.
(defun treemax (bilist &optional ismin)
(cond
;; Compute minimum
(ismin (min (COMPLEX_EXPRESSION_1) (COMPLEX_EXPRESSION_2)))
;; Compute maximum
(t (max (COMPLEX_EXPRESSION_1) (COMPLEX_EXPRESSION_2)))))
Run Code Online (Sandbox Code Playgroud)
这里的问题是COMPLEX_EXPRESSION_1和COMPLEX_EXPRESSION_2实际上占用了很多行代码.我真的不想重复它们.有没有更有效的方式来调用它?
基本上我要做的是一元 - 如果在函数而不是值.如果您熟悉C或其变体,基本上我正在寻找的概念是:
((ismin ? min : max) COMPLEX_EXPRESSION_1 COMPLEX_EXPRESSION_2)
Run Code Online (Sandbox Code Playgroud)
由此我有条件地选择发送参数的函数.这有意义吗?
c# ×5
wpf ×3
.net ×1
android ×1
android-ndk ×1
c ×1
c++ ×1
common-lisp ×1
linq ×1
lisp ×1
makefile ×1
perl ×1
screenshot ×1
uielement ×1
windows ×1
wpf-controls ×1
xaml ×1
xml ×1