对齐是实现定义的整数值,表示可以分配给定对象的连续地址之间的字节数.
这个概念有点不清楚.例如:
struct B { long double d; };
struct D : virtual B { char c; }
Run Code Online (Sandbox Code Playgroud)
当D是完整对象的类型时,它将具有类型B的子对象,因此它必须适当地对齐a
long double.
这是什么意思?sizeof(long double)是那种情况之间的字节数?
首先,我知道java中的字符串是不可变的.
我有一个关于String immutability的问题:
public static void stringReplace (String text)
{
text = text.replace ('j' , 'c'); /* Line 5 */
}
public static void bufferReplace (StringBuffer text)
{
text = text.append ("c"); /* Line 9 */
}
public static void main (String args[])
{
String textString = new String ("java");
StringBuffer textBuffer = new StringBuffer ("java"); /* Line 14 */
stringReplace(textString);
bufferReplace(textBuffer);
System.out.println (textString + textBuffer); //Prints javajavac
}
Run Code Online (Sandbox Code Playgroud)
但是如果我们写下以下内容:
public static void bufferReplace (StringBuffer text)
{
text = text.append …Run Code Online (Sandbox Code Playgroud) 我有以下枚举:
public enum RuleItem {
MORE_THAN(1) {
@Override
public String getStringRepresentation() {
return getRuleStringRepresentation("rulesName.moreThan");
}
},
LESS_THAN(2) {
@Override
public String getStringRepresentation() {
return getRuleStringRepresentation("rulesName.lessThan");
}
},
MORE_OR_EQUAL(3) {
@Override
public String getStringRepresentation() {
return getRuleStringRepresentation("rulesName.moreOrEqual");
}
},
//...
INTERVAL_WITH_BOUNDS_INCLUDED(27) {
@Override
public String getStringRepresentation() {
return getRuleStringRepresentation("rulesName.intervalWithBounds");
}
};
protected String getRuleStringRepresentation(String resourceName) {
Locale locale = FacesContext.getCurrentInstance().getViewRoot()
.getLocale();
String resourceString;
try {
ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME,
locale);
resourceString = bundle.getString(resourceName);
} catch (MissingResourceException e) {
return null;
} …Run Code Online (Sandbox Code Playgroud) 我有方面:
public aspect TestAspect {
pointcut publicMethodExecuted(): execution(public !static * *(..));
int around() : publicMethodExecuted() {
//I need parameters values here
//to write their to log
int original_return_value = proceed();
return original_return_value * 100;
}
}
Run Code Online (Sandbox Code Playgroud)
如何获取调用该方法的参数?我需要将它们写入日志文件.
我最感兴趣的是当地人AspectJ,而不是反思.
Java 7
我有一个界面:
public interface MyInt{
public Map<String, WhereClause> createClauses(Parameters<Object> params);
}
Run Code Online (Sandbox Code Playgroud)
以及它的一些实施:
public class MyImpl implements MyInt{
@Override
public Map<String, WhereClause> createClauses(Parameters<Object> p) { //1
//return some
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我可以将其返回类型设置为通用.我试过这个:
public interface MyInt <T extends SomeType>{
public Map<String, ? extends WhereClause> createClauses(Parameters<Object> params);
}
Run Code Online (Sandbox Code Playgroud)
但是我在实现中得到了编译时错误//1:
The method createClauses(Parameters<Object>) of type `MyImpl` must
override or implement a supertype method
Run Code Online (Sandbox Code Playgroud)
但是当我删除Generification时,实现编译得很好.
为什么即使不使用,也会影响编译type parameter.
我正在阅读J. Bloch的有效Java,现在我正在关于避免返回nulls,但返回空集合的部分.这是该部分的代码示例:
// The right way to return a copy of a collection
public List<Cheese> getCheeseList() {
if (cheesesInStock.isEmpty())
return Collections.emptyList(); // Always returns same list
else
return new ArrayList<Cheese>(cheesesInStock);
}
Run Code Online (Sandbox Code Playgroud)
我真的无法理解只返回cheesesInStockif 有什么问题cheesesInStock.isEmpty().为什么返回预定义更好Collections.emptyList().如果我们返回,我们可能遇到什么样的麻烦cheesesInStock.
我是新手Scala并查看了源代码Try::apply
def apply[T](r: => T): Try[T] =
try Success(r) catch {
case NonFatal(e) => Failure(e)
}
Run Code Online (Sandbox Code Playgroud)
它只是捕获非致命异常。但是如果我需要 finally 子句怎么办?是否可以以Try功能方式模拟它?我的意思是像
try{
//acquire lock
//do some
} finally {
// release lock
}
Run Code Online (Sandbox Code Playgroud)
和
Try{
//acquire lock
//do some
}
//Now how to release?
Run Code Online (Sandbox Code Playgroud) 我正在学习如何struct在C中使用s并编写以下示例:
#include <stdio.h>
#include <stdlib.h>
struct s1{
unsigned short member;
};
int main()
{
struct s1 *s1_ptr = malloc(sizeof(*s1_ptr));
s1_ptr -> member = 10;
printf("Member = %d\n", *s1_ptr); // Member = 10
}
Run Code Online (Sandbox Code Playgroud)
问题:在所有情况下,指向结构的指针是否与指向其第一个元素的指针完全相同?
在这个特殊的情况下,它按照我的预期工作,但我不确定它是否有保证.编译器是否可以在一开始就插入一些填充?
唯一我能找到的有关结构类型的布局是Section 6.2.5 Types的N1570:
结构类型描述顺序分配的非空成员对象集(并且在某些情况下,是不完整的数组),每个成员对象具有可选地指定的名称并且可能具有不同的类型.
但这里没有任何关于填充的信息.
C18标准指出6.7.9/2:
初始化程序不得尝试为未包含在正在初始化的实体中的对象提供值。
目前还不清楚这意味着什么。有一个相关主题:用于字符串初始化的Incretent gcc诊断。我引用的子句用于解释以下初始化产生的错误:
//error: excess elements in array initializer char a[5]
char a[5] = {'h','e','l','l','o','\0'};
Run Code Online (Sandbox Code Playgroud)
其中的initializer-list长度超过正在初始化的数组的大小。
但是考虑更简单的例子:
int main(void){
int a;
int b = (a = 3);
}
Run Code Online (Sandbox Code Playgroud)
这里的初始值设定项(a = 3)是assignment-expression。并且初始化程序为另一个对象分配一个值,这将导致违反约束。
为什么不打印任何诊断信息?
Whiskey Lake i7-8565U
我正在尝试学习如何手动编写基准测试(不使用任何基准测试框架)在一个内存复制例程示例中,使用常规和非临时性写入 WB 内存,并希望进行某种审查。
宣言:
void *avx_memcpy_forward_llss(void *restrict, const void *restrict, size_t);
void *avx_nt_memcpy_forward_llss(void *restrict, const void *restrict, size_t);
Run Code Online (Sandbox Code Playgroud)
定义:
avx_memcpy_forward_llss:
shr rdx, 0x3
xor rcx, rcx
avx_memcpy_forward_loop_llss:
vmovdqa ymm0, [rsi + 8*rcx]
vmovdqa ymm1, [rsi + 8*rcx + 0x20]
vmovdqa [rdi + rcx*8], ymm0
vmovdqa [rdi + rcx*8 + 0x20], ymm1
add rcx, 0x08
cmp rdx, rcx
ja avx_memcpy_forward_loop_llss
ret
avx_nt_memcpy_forward_llss:
shr rdx, 0x3
xor rcx, rcx
avx_nt_memcpy_forward_loop_llss:
vmovdqa ymm0, [rsi + 8*rcx]
vmovdqa ymm1, [rsi + …Run Code Online (Sandbox Code Playgroud)