一段C/C++代码可以为JNI方法提供一个函数指针数组.但是有没有办法直接从Java代码内部(不使用JNI或类似代码)调用数组指针指向的函数?JNI以某种方式做了类似的事情,所以必须有办法.JNI是如何做到的?是通过sun.misc.Unsafe吗?即使不是,我们是否可以使用一些不安全的解决方法来获取执行此操作的JVM代码?
我当然不打算在商业上使用它.我甚至不是专业人士,我只是非常喜欢编码而且我最近一直在研究CUDA所以我想也许我可以尝试将所有东西混合在一起,但JNI调用的开销会破坏GPU加速代码的目的.
例如,我想创建注释@Out来定位参数.然后我会以某种方式使用编译器来检查函数返回之前是否设置了参数值.这可能吗?
还考虑了一个@Immutable注释,该注释不允许调用任何未使用@Const注释的方法或访问任何公共字段.(编译时间,可能是运行时?)
到目前为止我有这个:
//I'm assuming Class retention is a subset of Runtime retention
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface Out
{
//no idea what to go in here.
}
Run Code Online (Sandbox Code Playgroud)
这是另一个注释.再次,我没有完整的定义:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Immutable
{
}
Run Code Online (Sandbox Code Playgroud)
我想我可以开始设计一个策略来在运行时使用反射来实现它,但我想指示编译器或预处理器为我检查那些东西,所以我的注释将没有开销.
这是你认为"如果可以做到这一点,那就已经存在了,如果是这样的话,那我可以抓住它".
编辑:经过进一步思考@Const
,并@Immutable
和记忆的Java按值传递对象指针后,我扩大的定义@Const
,摆脱@Immutable
和改变的定义@Out
,如波纹管如下:
/**
* When Applied to a method, ensures the method doesn't change in any
* way the state of the object used to invoke it, i.e., all the fields
* of …
Run Code Online (Sandbox Code Playgroud) 我是AST的新手(我第一次写插件).表达在现实生活中可能相当复杂.例如,我想知道如何解决对齐的左侧和右侧.
class Visitor extends ASTVisitor
{
@Override
public boolean visit(Assignment node)
{
//here, how do I get the final name to each each side of the assignment resolves?
}
}
Run Code Online (Sandbox Code Playgroud)
我还有另一个疑问,我如何获取用于调用方法的实例?
public boolean visit(MethodInvocation node)
{
//how do I get to know the object used to invoke this method?
//like, for example, MyClass is a class, and it has a field called myField
//the type of myField has a method called myMethod.
//how do I find myField? or for that …
Run Code Online (Sandbox Code Playgroud) 我知道这个问题的术语一定是错的,但请耐心等待,并尝试从我的外行角度看待事物(我没有计算机技术方面的知识,我是自学爱好者。我得到的最接近的编程语言方面的正规教育是我学校的机器人俱乐部)。
我想要的是能够使用托管 DirectX 12 作为我的应用程序的“背景”,以及游戏循环和所有内容。并且,如果可能的话,能够在实际的 DirectX 游戏周围拥有 WPF 控件,如功能区或工具箱或菜单。我一直在寻找互联网上的所有内容,我发现的都是适用于 Windows 和 DirectX 9.0 的旧东西;我希望这些天有新的东西。
我尝试了 Windows 窗体方法,基本上是这样的:
using System;
using System.Windows;
using System.Windows.Interop;
using Microsoft.DirectX.Direct3D;
using DColor = System.Drawing.Color;
public partial class MainWindow : Window
{
Device device;
public MainWindow()
{
InitializeComponent();
initDevice();
}
private void initDevice()
{
try
{
PresentParameters parameters = new PresentParameters();
parameters.Windowed = true;
parameters.SwapEffect = SwapEffect.Discard;
IntPtr windowHandle = new WindowInteropHelper(this).Handle;
device = new Device(0, DeviceType.Hardware, windowHandle, CreateFlags.HardwareVertexProcessing, parameters);
}
catch(Exception e)
{
MessageBox.Show("initDevice threw …
Run Code Online (Sandbox Code Playgroud) 我正在检查此图表,其中包含列表之间的性能比较:
而且我发现在特定索引处添加和删除元素的速度ArrayList
比在a中执行速度快得多LinkedList
.这个图表错了吗?a的整体思想LinkedList
是改进这样的操作,同时以降低的迭代性能付费.但是这个图表似乎表明Java的实现LinkedLists
做得非常糟糕.
我应该相信图表吗?如果是这样,为什么Java LinkedLists
表现如此糟糕?
首先,我想通过对文本中的点击进行透明来定义我的意思:这意味着点击进入我的窗口而不进行任何处理,直接到下面的任何窗口.我需要这种行为,因为这个应用程序是一个覆盖游戏.
我搜索了有关使窗口对点击透明的问题.我想知道是否有办法让窗口本身对点击是透明的,而不是它的控件(如文本框和按钮).
这是窗口的标记:
<Window x:Class="QuestBrowser.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Quest Browser"
Height="350" Width="525"
AllowsTransparency="True" WindowStyle="None" Topmost="True">
<Window.Background>
<SolidColorBrush Color="White" Opacity="0.1"/>
</Window.Background>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBox Name="inputTxtBox"></TextBox>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
而bellow是使窗口对点击透明的代码(几乎从其他问题复制粘贴,因为我在低级Windows编程时并不擅长).
namespace Win32Utils
{
public static class WindowHelper
{
const int WS_EX_TRANSPARENT = 0x00000020;
const int GWL_EXSTYLE = (-20);
public static void SetWindowExTransparent(IntPtr hwnd)
{
var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
}
}
}
Run Code Online (Sandbox Code Playgroud)
WindowHelper.SetWindowExTransparent方法是在我的方法Window.OnSourceInitialized的覆盖范围内调用的(正如我在获得透明窗口代码的帖子中所指示的):
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
var hwnd …
Run Code Online (Sandbox Code Playgroud) 我所追求的多态性类型是这样的:
假设我有一个名为draw()的宏,我有2个结构,一个叫做圆圈,另一个叫做方形.有可能以某种方式做这样的事情:
#define draw() // can I get the text that's behind the macro?
//then maybe, with _Generic achieve this?
void draw_circle(struct circle);
void draw_square(struct square);
struct circle c;
struct square s;
c.draw();//draw is a macro. this time it is supposed to expand to draw_circle(c);
s.draw();//supposed to expand to draw_square(s);
Run Code Online (Sandbox Code Playgroud)
EDIT_1:在阅读完答案之后,这是我到目前为止所做的.
//raw_array.h
#pragma once
#include <stdint.h>
#include <stdlib.h>
#define byte uint8_t
#define _GET_OVERRIDE(_1, _2, _3, NAME, ...) NAME
/*#define init_impl(...) _GET_OVERRIDE(__VA_ARGS__, \
init_impl3, init_impl2, init_impl1)(__VA_ARGS__)
#define init( name, ... …
Run Code Online (Sandbox Code Playgroud) 我没有GUI(我的课程是Minecraft Mod的一部分)。我希望能够模仿C#事件框架:一个类声明事件并让其他人订阅它们。
我的第一种方法是创建一个名为的类EventArgs
,然后执行以下操作:
public class EventArgs
{
public boolean handled;
}
@FunctionalInterface
public interface IEventHandler<TEvtArgs extends EventArgs>
{
public void handle(Object source, TEvtArgs args);
}
public class Event<TEvtArgs extends EventArgs>
{
private final Object owner;
private final LinkedList<IEventHandler<TEvtArgs>> handlers = new LinkedList<>();
public Event(Object owner)
{
this.owner = owner;
}
public void subscribe(IEventHandler<TEvtArgs> handler)
{
handlers.add(handler);
}
public void unsubscribe(IEventHandler<TEvtArgs> handler)
{
while(handlers.remove(handler));
}
public void raise(TEvtArgs args)
{
for(IEventHandler<TEvtArgs> handler : handlers)
{
handler.handle(owner, args);
if(args.handled)
break; …
Run Code Online (Sandbox Code Playgroud) 是否有一个函数可以迭代用户数据值中的条目?我试图列出某个用户数据变量中的每个字段及其值,就像这样pairs
做:
local function list_entries ( obj )
for k, v in pairs ( obj ) do
print ( k .. ": " .. tostring ( v ) )
end
end
Run Code Online (Sandbox Code Playgroud)
pairs
不适用于用户数据,那么有解决方案吗?
我必须写一个C#脚本,我不得不担心三件事:性能,字符数和行数(只允许一个分号).我需要连接字符串列表,这是我目前的方法(为了便于阅读,稍微修改了片段,更改了变量名称并添加了空格):
//note: stringList is of type List<string>
var builder = new StringBuilder();
string result = (from str in stringList select builder.Append("&q=" + str)).ToString();
Run Code Online (Sandbox Code Playgroud)
这个问题是它有两行,所以它不起作用.有没有办法在LINQ查询中实例化字符串生成器?
此外,与简单的foreach循环相比,此查询的性能有多好?(我知道foreach不是一个选项,我只是要求将来参考)
java ×5
c# ×3
c ×2
eclipse ×2
performance ×2
wpf ×2
annotations ×1
arraylist ×1
directx-12 ×1
eclipse-jdt ×1
events ×1
interop ×1
jvm ×1
linked-list ×1
linq ×1
lua ×1
macros ×1
native-code ×1
winapi ×1